mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-02 18:41:35 +08:00
fix(opencode): add missing omo-slim category checks across add/form/mutation paths
Several code paths only checked for "omo" category but missed "omo-slim", causing OMO Slim providers to be treated as regular OpenCode providers (triggering invalid write_live_snapshot, requiring manual provider key, and showing wrong form fields).
This commit is contained in:
@@ -133,10 +133,11 @@ impl ProviderService {
|
|||||||
|
|
||||||
// Additive mode apps (OpenCode, OpenClaw) - always write to live config
|
// Additive mode apps (OpenCode, OpenClaw) - always write to live config
|
||||||
if app_type.is_additive_mode() {
|
if app_type.is_additive_mode() {
|
||||||
// OMO providers use exclusive mode and write to dedicated config file.
|
// OMO / OMO Slim providers use exclusive mode and write to dedicated config file.
|
||||||
if matches!(app_type, AppType::OpenCode) && provider.category.as_deref() == Some("omo")
|
if matches!(app_type, AppType::OpenCode)
|
||||||
|
&& matches!(provider.category.as_deref(), Some("omo") | Some("omo-slim"))
|
||||||
{
|
{
|
||||||
// Do not auto-enable newly added OMO providers.
|
// Do not auto-enable newly added OMO / OMO Slim providers.
|
||||||
// Users must explicitly switch/apply an OMO provider to activate it.
|
// Users must explicitly switch/apply an OMO provider to activate it.
|
||||||
return Ok(true);
|
return Ok(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -551,7 +551,7 @@ export function ProviderForm({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appId === "opencode" && category !== "omo") {
|
if (appId === "opencode" && !isAnyOmoCategory) {
|
||||||
const keyPattern = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
const keyPattern = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
||||||
if (!opencodeForm.opencodeProviderKey.trim()) {
|
if (!opencodeForm.opencodeProviderKey.trim()) {
|
||||||
toast.error(t("opencode.providerKeyRequired"));
|
toast.error(t("opencode.providerKeyRequired"));
|
||||||
@@ -732,9 +732,10 @@ export function ProviderForm({
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (appId === "opencode") {
|
if (appId === "opencode") {
|
||||||
if (category === "omo") {
|
if (isAnyOmoCategory) {
|
||||||
if (!isEditMode) {
|
if (!isEditMode) {
|
||||||
payload.providerKey = `omo-${crypto.randomUUID().slice(0, 8)}`;
|
const prefix = category === "omo" ? "omo" : "omo-slim";
|
||||||
|
payload.providerKey = `${prefix}-${crypto.randomUUID().slice(0, 8)}`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
payload.providerKey = opencodeForm.opencodeProviderKey;
|
payload.providerKey = opencodeForm.opencodeProviderKey;
|
||||||
@@ -743,8 +744,8 @@ export function ProviderForm({
|
|||||||
payload.providerKey = openclawForm.openclawProviderKey;
|
payload.providerKey = openclawForm.openclawProviderKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category === "omo" && !payload.presetCategory) {
|
if (isAnyOmoCategory && !payload.presetCategory) {
|
||||||
payload.presetCategory = "omo";
|
payload.presetCategory = category;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activePreset) {
|
if (activePreset) {
|
||||||
@@ -1000,10 +1001,10 @@ export function ProviderForm({
|
|||||||
const preset = entry.preset as OpenCodeProviderPreset;
|
const preset = entry.preset as OpenCodeProviderPreset;
|
||||||
const config = preset.settingsConfig;
|
const config = preset.settingsConfig;
|
||||||
|
|
||||||
if (preset.category === "omo") {
|
if (preset.category === "omo" || preset.category === "omo-slim") {
|
||||||
omoDraft.resetOmoDraftState();
|
omoDraft.resetOmoDraftState();
|
||||||
form.reset({
|
form.reset({
|
||||||
name: "OMO",
|
name: preset.category === "omo" ? "OMO" : "OMO Slim",
|
||||||
websiteUrl: preset.websiteUrl ?? "",
|
websiteUrl: preset.websiteUrl ?? "",
|
||||||
settingsConfig: JSON.stringify({}, null, 2),
|
settingsConfig: JSON.stringify({}, null, 2),
|
||||||
icon: preset.icon ?? "",
|
icon: preset.icon ?? "",
|
||||||
@@ -1113,7 +1114,7 @@ export function ProviderForm({
|
|||||||
<BasicFormFields
|
<BasicFormFields
|
||||||
form={form}
|
form={form}
|
||||||
beforeNameSlot={
|
beforeNameSlot={
|
||||||
appId === "opencode" && category !== "omo" ? (
|
appId === "opencode" && !isAnyOmoCategory ? (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="opencode-key">
|
<Label htmlFor="opencode-key">
|
||||||
{t("opencode.providerKey")}
|
{t("opencode.providerKey")}
|
||||||
@@ -1337,7 +1338,7 @@ export function ProviderForm({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{appId === "opencode" && category !== "omo" && (
|
{appId === "opencode" && !isAnyOmoCategory && (
|
||||||
<OpenCodeFormFields
|
<OpenCodeFormFields
|
||||||
npm={opencodeForm.opencodeNpm}
|
npm={opencodeForm.opencodeNpm}
|
||||||
onNpmChange={opencodeForm.handleOpencodeNpmChange}
|
onNpmChange={opencodeForm.handleOpencodeNpmChange}
|
||||||
@@ -1531,7 +1532,7 @@ export function ProviderForm({
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{category !== "omo" && appId !== "opencode" && appId !== "openclaw" && (
|
{!isAnyOmoCategory && appId !== "opencode" && appId !== "openclaw" && (
|
||||||
<ProviderAdvancedConfig
|
<ProviderAdvancedConfig
|
||||||
testConfig={testConfig}
|
testConfig={testConfig}
|
||||||
proxyConfig={proxyConfig}
|
proxyConfig={proxyConfig}
|
||||||
|
|||||||
@@ -19,8 +19,12 @@ export const useAddProviderMutation = (appId: AppId) => {
|
|||||||
let id: string;
|
let id: string;
|
||||||
|
|
||||||
if (appId === "opencode" || appId === "openclaw") {
|
if (appId === "opencode" || appId === "openclaw") {
|
||||||
if (providerInput.category === "omo") {
|
if (
|
||||||
id = `omo-${generateUUID()}`;
|
providerInput.category === "omo" ||
|
||||||
|
providerInput.category === "omo-slim"
|
||||||
|
) {
|
||||||
|
const prefix = providerInput.category === "omo" ? "omo" : "omo-slim";
|
||||||
|
id = `${prefix}-${generateUUID()}`;
|
||||||
} else {
|
} else {
|
||||||
if (!providerInput.providerKey) {
|
if (!providerInput.providerKey) {
|
||||||
throw new Error(`Provider key is required for ${appId}`);
|
throw new Error(`Provider key is required for ${appId}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user