chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 12:22:33 +08:00
commit fc4fcbab58
1848 changed files with 472303 additions and 0 deletions
@@ -0,0 +1,157 @@
import AppKit
import CodexBarCore
import Foundation
import SwiftUI
struct StepFunProviderImplementation: ProviderImplementation {
let id: UsageProvider = .stepfun
@MainActor
func presentation(context _: ProviderPresentationContext) -> ProviderPresentation {
ProviderPresentation { _ in "web" }
}
@MainActor
func observeSettings(_ settings: SettingsStore) {
_ = settings.stepfunCookieSource
_ = settings.stepfunUsername
_ = settings.stepfunPassword
_ = settings.stepfunToken
}
@MainActor
func isAvailable(context: ProviderAvailabilityContext) -> Bool {
// Available if any auth method is configured
if !context.settings.stepfunUsername.isEmpty, !context.settings.stepfunPassword.isEmpty {
return true
}
if context.settings.stepfunCookieSource == .manual, !context.settings.stepfunToken.isEmpty {
return true
}
if CookieHeaderCache.load(provider: .stepfun) != nil {
return true
}
if StepFunSettingsReader.username(environment: context.environment) != nil,
StepFunSettingsReader.password(environment: context.environment) != nil
{
return true
}
if StepFunSettingsReader.token(environment: context.environment) != nil {
return true
}
return false
}
@MainActor
func settingsSnapshot(context: ProviderSettingsSnapshotContext) -> ProviderSettingsSnapshotContribution? {
.stepfun(context.settings.stepfunSettingsSnapshot(tokenOverride: context.tokenOverride))
}
@MainActor
func tokenAccountsVisibility(context: ProviderSettingsContext, support: TokenAccountSupport) -> Bool {
guard support.requiresManualCookieSource else { return true }
if !context.settings.tokenAccounts(for: context.provider).isEmpty { return true }
return context.settings.stepfunCookieSource == .manual
}
@MainActor
func applyTokenAccountCookieSource(settings: SettingsStore) {
if settings.stepfunCookieSource != .manual {
settings.stepfunCookieSource = .manual
}
}
// MARK: - Settings Pickers
@MainActor
func settingsPickers(context: ProviderSettingsContext) -> [ProviderSettingsPickerDescriptor] {
let cookieBinding = Binding(
get: { context.settings.stepfunCookieSource.rawValue },
set: { raw in
context.settings.stepfunCookieSource = ProviderCookieSource(rawValue: raw) ?? .auto
})
let cookieOptions = ProviderCookieSourceUI.options(
allowsOff: true,
keychainDisabled: context.settings.debugDisableKeychainAccess)
let cookieSubtitle: () -> String? = {
ProviderCookieSourceUI.subtitle(
source: context.settings.stepfunCookieSource,
keychainDisabled: context.settings.debugDisableKeychainAccess,
auto: "Uses username + password to login and obtain an Oasis-Token automatically.",
manual: "Manually paste an Oasis-Token from a browser session.",
off: "StepFun authentication is disabled.")
}
return [
ProviderSettingsPickerDescriptor(
id: "stepfun-cookie-source",
title: "Auth source",
subtitle: "Uses username + password to login and obtain an Oasis-Token automatically.",
dynamicSubtitle: cookieSubtitle,
binding: cookieBinding,
options: cookieOptions,
isVisible: nil,
onChange: nil,
trailingText: {
ProviderCookieSourceUI.cachedTrailingText(provider: .stepfun)
}),
]
}
// MARK: - Settings Fields
@MainActor
func settingsFields(context: ProviderSettingsContext) -> [ProviderSettingsFieldDescriptor] {
// Auto mode: show username + password fields
let autoFields: [ProviderSettingsFieldDescriptor] = [
ProviderSettingsFieldDescriptor(
id: "stepfun-username",
title: "Username",
subtitle: "StepFun platform account (phone number or email).",
kind: .plain,
placeholder: "user@example.com",
binding: context.stringBinding(\.stepfunUsername),
actions: [],
isVisible: { context.settings.stepfunCookieSource != .manual },
onActivate: nil),
ProviderSettingsFieldDescriptor(
id: "stepfun-password",
title: "Password",
subtitle: "Your StepFun platform password. Used to login and obtain a session token.",
kind: .secure,
placeholder: "Password",
binding: context.stringBinding(\.stepfunPassword),
actions: [],
isVisible: { context.settings.stepfunCookieSource != .manual },
onActivate: nil),
]
// Manual mode: show token field
let manualFields: [ProviderSettingsFieldDescriptor] = [
ProviderSettingsFieldDescriptor(
id: "stepfun-token",
title: "Oasis-Token",
subtitle: "Paste the Oasis-Token from a logged-in browser session on platform.stepfun.com.",
kind: .secure,
placeholder: "Oasis-Token=…",
binding: context.stringBinding(\.stepfunToken),
actions: [
ProviderSettingsActionDescriptor(
id: "stepfun-open-platform",
title: "Open StepFun Platform",
style: .link,
isVisible: nil,
perform: {
if let url = URL(string: "https://platform.stepfun.com/plan-usage") {
NSWorkspace.shared.open(url)
}
}),
],
isVisible: { context.settings.stepfunCookieSource == .manual },
onActivate: nil),
]
return autoFields + manualFields
}
}
@@ -0,0 +1,65 @@
import CodexBarCore
import Foundation
extension SettingsStore {
/// Username for StepFun login stored in the apiKey config field.
var stepfunUsername: String {
get { self.configSnapshot.providerConfig(for: .stepfun)?.sanitizedAPIKey ?? "" }
set {
self.updateProviderConfig(provider: .stepfun) { entry in
entry.apiKey = self.normalizedConfigValue(newValue)
}
self.logProviderModeChange(
provider: .stepfun,
field: "username",
value: newValue.isEmpty ? "(cleared)" : "(updated)")
}
}
/// Password for StepFun login stored in the cookieHeader config field (secure storage).
var stepfunPassword: String {
get { self.configSnapshot.providerConfig(for: .stepfun)?.sanitizedCookieHeader ?? "" }
set {
self.updateProviderConfig(provider: .stepfun) { entry in
entry.cookieHeader = self.normalizedConfigValue(newValue)
}
self.logSecretUpdate(provider: .stepfun, field: "password", value: newValue)
}
}
/// Manual Oasis-Token stored in the region config field (repurposed for token).
var stepfunToken: String {
get { self.configSnapshot.providerConfig(for: .stepfun)?.region ?? "" }
set {
self.updateProviderConfig(provider: .stepfun) { entry in
entry.region = self.normalizedConfigValue(newValue)
}
self.logSecretUpdate(provider: .stepfun, field: "token", value: newValue)
}
}
var stepfunCookieSource: ProviderCookieSource {
get { self.resolvedCookieSource(provider: .stepfun, fallback: .auto) }
set {
self.updateProviderConfig(provider: .stepfun) { entry in
entry.cookieSource = newValue
}
self.logProviderModeChange(provider: .stepfun, field: "cookieSource", value: newValue.rawValue)
}
}
func stepfunSettingsSnapshot(tokenOverride: TokenAccountOverride?) -> ProviderSettingsSnapshot
.StepFunProviderSettings
{
let cookieSettings: ProviderSettingsSnapshot.CookieProviderSettings = self.resolvedCookieSettings(
provider: .stepfun,
configuredSource: self.stepfunCookieSource,
configuredHeader: self.stepfunToken,
tokenOverride: tokenOverride)
return ProviderSettingsSnapshot.StepFunProviderSettings(
cookieSource: cookieSettings.cookieSource,
manualToken: cookieSettings.manualCookieHeader ?? "",
username: self.stepfunUsername,
password: self.stepfunPassword)
}
}