mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-24 10:13:11 +02:00
Address ACPX adapter config review
This commit is contained in:
1 parent
3c84a47cab
commit
c971bbfacd
5 files changed
+85
-19
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { AdapterConfigSchema, ConfigFieldSchema } from "@paperclipai/adapter-utils";
|
||||
import { fieldMatchesVisibleWhen } from "./schema-config-fields";
|
||||
|
||||
const sourceField: ConfigFieldSchema = {
|
||||
key: "provider",
|
||||
label: "Provider",
|
||||
type: "select",
|
||||
options: [
|
||||
{ label: "Claude", value: "claude" },
|
||||
{ label: "Codex", value: "codex" },
|
||||
],
|
||||
};
|
||||
|
||||
const schema: AdapterConfigSchema = {
|
||||
fields: [sourceField],
|
||||
};
|
||||
|
||||
function targetWithVisibleWhen(visibleWhen: Record<string, unknown>): ConfigFieldSchema {
|
||||
return {
|
||||
key: "model",
|
||||
label: "Model",
|
||||
type: "text",
|
||||
meta: { visibleWhen },
|
||||
};
|
||||
}
|
||||
|
||||
describe("fieldMatchesVisibleWhen", () => {
|
||||
it("treats an empty values array as no match", () => {
|
||||
const field = targetWithVisibleWhen({ key: "provider", values: [] });
|
||||
|
||||
expect(fieldMatchesVisibleWhen(field, () => "claude", schema)).toBe(false);
|
||||
});
|
||||
|
||||
it("treats all non-string values as no match", () => {
|
||||
const field = targetWithVisibleWhen({ key: "provider", values: [null, 42] });
|
||||
|
||||
expect(fieldMatchesVisibleWhen(field, () => "claude", schema)).toBe(false);
|
||||
});
|
||||
|
||||
it("matches non-empty string values", () => {
|
||||
const field = targetWithVisibleWhen({ key: "provider", values: ["claude"] });
|
||||
|
||||
expect(fieldMatchesVisibleWhen(field, () => "claude", schema)).toBe(true);
|
||||
expect(fieldMatchesVisibleWhen(field, () => "codex", schema)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -283,7 +283,7 @@ function getDefaultValue(field: ConfigFieldSchema): unknown {
|
||||
}
|
||||
}
|
||||
|
||||
function fieldMatchesVisibleWhen(
|
||||
export function fieldMatchesVisibleWhen(
|
||||
field: ConfigFieldSchema,
|
||||
readValue: (field: ConfigFieldSchema) => unknown,
|
||||
schema: AdapterConfigSchema,
|
||||
@@ -306,7 +306,7 @@ function fieldMatchesVisibleWhen(
|
||||
if (typeof condition.value === "string") return actual === condition.value;
|
||||
if (Array.isArray(condition.values)) {
|
||||
const values = condition.values.filter((value): value is string => typeof value === "string");
|
||||
return values.length === 0 || values.includes(actual);
|
||||
return values.length > 0 && values.includes(actual);
|
||||
}
|
||||
if (Array.isArray(condition.notValues)) {
|
||||
const values = condition.notValues.filter((value): value is string => typeof value === "string");
|
||||
|
||||
@@ -57,6 +57,7 @@ import { getAdapterDisplay, getAdapterLabel } from "../adapters/adapter-display-
|
||||
import { useDisabledAdaptersSync } from "../adapters/use-disabled-adapters";
|
||||
import { buildAgentUpdatePatch, type AgentConfigOverlay } from "../lib/agent-config-patch";
|
||||
import { useAdapterCapabilities } from "../adapters/use-adapter-capabilities";
|
||||
import { filterAcpxModelsByAgent } from "../lib/acpx-model-filter";
|
||||
|
||||
/* ---- Create mode values ---- */
|
||||
|
||||
@@ -360,9 +361,21 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||
});
|
||||
const [refreshModelsError, setRefreshModelsError] = useState<string | null>(null);
|
||||
const [refreshingModels, setRefreshingModels] = useState(false);
|
||||
const models = fetchedModels ?? externalModels ?? [];
|
||||
const rawModels = fetchedModels ?? externalModels ?? [];
|
||||
const adapterCommandField =
|
||||
adapterType === "hermes_local" ? "hermesCommand" : "command";
|
||||
const acpxAgent =
|
||||
adapterType === "acpx_local"
|
||||
? isCreate
|
||||
? String(val!.adapterSchemaValues?.agent ?? "claude")
|
||||
: eff("adapterConfig", "agent", String(config.agent ?? "claude"))
|
||||
: "";
|
||||
const models = useMemo(
|
||||
() => adapterType === "acpx_local"
|
||||
? filterAcpxModelsByAgent(rawModels, acpxAgent)
|
||||
: rawModels,
|
||||
[adapterType, rawModels, acpxAgent],
|
||||
);
|
||||
const {
|
||||
data: detectedModelData,
|
||||
refetch: refetchDetectedModel,
|
||||
@@ -509,12 +522,6 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||
const currentModelId = isCreate
|
||||
? val!.model
|
||||
: eff("adapterConfig", "model", String(config.model ?? ""));
|
||||
const acpxAgent =
|
||||
adapterType === "acpx_local"
|
||||
? isCreate
|
||||
? String(val!.adapterSchemaValues?.agent ?? "claude")
|
||||
: eff("adapterConfig", "agent", String(config.agent ?? "claude"))
|
||||
: "";
|
||||
|
||||
async function handleRefreshModels() {
|
||||
if (!selectedCompanyId) return;
|
||||
|
||||
Reference in new issue
Block a user