feat(adapters): add capability flags to ServerAdapterModule
Replace 5 hardcoded adapter type lists with declarative capability flags on ServerAdapterModule, enabling external adapter plugins to declare their capabilities without modifying Paperclip source. New optional fields on ServerAdapterModule: - supportsInstructionsBundle: managed instructions bundle support - instructionsPathKey: config key for instructions file path - requiresMaterializedRuntimeSkills: skill materialization needed Server changes: - agents.ts: capability-aware helpers with legacy fallbacks - adapters.ts: expose capabilities in GET /api/adapters response - registry.ts: explicit flags on all built-in adapters UI changes: - New useAdapterCapabilities hook for capability lookups - AgentDetail.tsx: replace hardcoded isLocal allowlist - AgentConfigForm.tsx: replace NONLOCAL_TYPES denylist - OnboardingWizard.tsx: replace NONLOCAL_TYPES denylist All flags are optional with backwards-compatible fallbacks to the legacy hardcoded lists for adapters that don't set them. Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -97,6 +97,9 @@ const claudeLocalAdapter: ServerAdapterModule = {
|
||||
models: claudeModels,
|
||||
listModels: listClaudeModels,
|
||||
supportsLocalAgentJwt: true,
|
||||
supportsInstructionsBundle: true,
|
||||
instructionsPathKey: "instructionsFilePath",
|
||||
requiresMaterializedRuntimeSkills: false,
|
||||
agentConfigurationDoc: claudeAgentConfigurationDoc,
|
||||
getQuotaWindows: claudeGetQuotaWindows,
|
||||
};
|
||||
@@ -112,6 +115,9 @@ const codexLocalAdapter: ServerAdapterModule = {
|
||||
models: codexModels,
|
||||
listModels: listCodexModels,
|
||||
supportsLocalAgentJwt: true,
|
||||
supportsInstructionsBundle: true,
|
||||
instructionsPathKey: "instructionsFilePath",
|
||||
requiresMaterializedRuntimeSkills: false,
|
||||
agentConfigurationDoc: codexAgentConfigurationDoc,
|
||||
getQuotaWindows: codexGetQuotaWindows,
|
||||
};
|
||||
@@ -127,6 +133,9 @@ const cursorLocalAdapter: ServerAdapterModule = {
|
||||
models: cursorModels,
|
||||
listModels: listCursorModels,
|
||||
supportsLocalAgentJwt: true,
|
||||
supportsInstructionsBundle: true,
|
||||
instructionsPathKey: "instructionsFilePath",
|
||||
requiresMaterializedRuntimeSkills: true,
|
||||
agentConfigurationDoc: cursorAgentConfigurationDoc,
|
||||
};
|
||||
|
||||
@@ -140,6 +149,9 @@ const geminiLocalAdapter: ServerAdapterModule = {
|
||||
sessionManagement: getAdapterSessionManagement("gemini_local") ?? undefined,
|
||||
models: geminiModels,
|
||||
supportsLocalAgentJwt: true,
|
||||
supportsInstructionsBundle: true,
|
||||
instructionsPathKey: "instructionsFilePath",
|
||||
requiresMaterializedRuntimeSkills: true,
|
||||
agentConfigurationDoc: geminiAgentConfigurationDoc,
|
||||
};
|
||||
|
||||
@@ -149,6 +161,8 @@ const openclawGatewayAdapter: ServerAdapterModule = {
|
||||
testEnvironment: openclawGatewayTestEnvironment,
|
||||
models: openclawGatewayModels,
|
||||
supportsLocalAgentJwt: false,
|
||||
supportsInstructionsBundle: false,
|
||||
requiresMaterializedRuntimeSkills: false,
|
||||
agentConfigurationDoc: openclawGatewayAgentConfigurationDoc,
|
||||
};
|
||||
|
||||
@@ -163,6 +177,9 @@ const openCodeLocalAdapter: ServerAdapterModule = {
|
||||
sessionManagement: getAdapterSessionManagement("opencode_local") ?? undefined,
|
||||
listModels: listOpenCodeModels,
|
||||
supportsLocalAgentJwt: true,
|
||||
supportsInstructionsBundle: true,
|
||||
instructionsPathKey: "instructionsFilePath",
|
||||
requiresMaterializedRuntimeSkills: true,
|
||||
agentConfigurationDoc: openCodeAgentConfigurationDoc,
|
||||
};
|
||||
|
||||
@@ -177,6 +194,9 @@ const piLocalAdapter: ServerAdapterModule = {
|
||||
models: [],
|
||||
listModels: listPiModels,
|
||||
supportsLocalAgentJwt: true,
|
||||
supportsInstructionsBundle: true,
|
||||
instructionsPathKey: "instructionsFilePath",
|
||||
requiresMaterializedRuntimeSkills: true,
|
||||
agentConfigurationDoc: piAgentConfigurationDoc,
|
||||
};
|
||||
|
||||
@@ -189,6 +209,9 @@ const hermesLocalAdapter: ServerAdapterModule = {
|
||||
syncSkills: hermesSyncSkills,
|
||||
models: hermesModels,
|
||||
supportsLocalAgentJwt: true,
|
||||
supportsInstructionsBundle: true,
|
||||
instructionsPathKey: "instructionsFilePath",
|
||||
requiresMaterializedRuntimeSkills: false,
|
||||
agentConfigurationDoc: hermesAgentConfigurationDoc,
|
||||
detectModel: () => detectModelFromHermes(),
|
||||
};
|
||||
|
||||
@@ -59,6 +59,13 @@ interface AdapterInstallRequest {
|
||||
version?: string;
|
||||
}
|
||||
|
||||
interface AdapterCapabilities {
|
||||
supportsInstructionsBundle: boolean;
|
||||
supportsSkills: boolean;
|
||||
supportsLocalAgentJwt: boolean;
|
||||
requiresMaterializedRuntimeSkills: boolean;
|
||||
}
|
||||
|
||||
interface AdapterInfo {
|
||||
type: string;
|
||||
label: string;
|
||||
@@ -66,6 +73,7 @@ interface AdapterInfo {
|
||||
modelsCount: number;
|
||||
loaded: boolean;
|
||||
disabled: boolean;
|
||||
capabilities: AdapterCapabilities;
|
||||
/** True when an external plugin has replaced a built-in adapter of the same type. */
|
||||
overriddenBuiltin?: boolean;
|
||||
/** True when the external override for a builtin type is currently paused. */
|
||||
@@ -103,6 +111,15 @@ function readAdapterPackageVersionFromDisk(record: AdapterPluginRecord): string
|
||||
}
|
||||
}
|
||||
|
||||
function buildAdapterCapabilities(adapter: ServerAdapterModule): AdapterCapabilities {
|
||||
return {
|
||||
supportsInstructionsBundle: adapter.supportsInstructionsBundle ?? false,
|
||||
supportsSkills: Boolean(adapter.listSkills || adapter.syncSkills),
|
||||
supportsLocalAgentJwt: adapter.supportsLocalAgentJwt ?? false,
|
||||
requiresMaterializedRuntimeSkills: adapter.requiresMaterializedRuntimeSkills ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
function buildAdapterInfo(adapter: ServerAdapterModule, externalRecord: AdapterPluginRecord | undefined, disabledSet: Set<string>): AdapterInfo {
|
||||
const fromDisk = externalRecord ? readAdapterPackageVersionFromDisk(externalRecord) : undefined;
|
||||
return {
|
||||
@@ -112,6 +129,7 @@ function buildAdapterInfo(adapter: ServerAdapterModule, externalRecord: AdapterP
|
||||
modelsCount: (adapter.models ?? []).length,
|
||||
loaded: true, // If it's in the registry, it's loaded
|
||||
disabled: disabledSet.has(adapter.type),
|
||||
capabilities: buildAdapterCapabilities(adapter),
|
||||
overriddenBuiltin: externalRecord ? BUILTIN_ADAPTER_TYPES.has(adapter.type) : undefined,
|
||||
overridePaused: BUILTIN_ADAPTER_TYPES.has(adapter.type) ? isOverridePaused(adapter.type) : undefined,
|
||||
// Prefer on-disk package.json so the UI reflects bumps without relying on store-only fields.
|
||||
|
||||
@@ -72,6 +72,8 @@ import {
|
||||
import { getTelemetryClient } from "../telemetry.js";
|
||||
|
||||
export function agentRoutes(db: Db) {
|
||||
// Legacy hardcoded maps — used as fallback when adapter module does not
|
||||
// declare capability flags explicitly.
|
||||
const DEFAULT_INSTRUCTIONS_PATH_KEYS: Record<string, string> = {
|
||||
claude_local: "instructionsFilePath",
|
||||
codex_local: "instructionsFilePath",
|
||||
@@ -83,6 +85,20 @@ export function agentRoutes(db: Db) {
|
||||
pi_local: "instructionsFilePath",
|
||||
};
|
||||
const DEFAULT_MANAGED_INSTRUCTIONS_ADAPTER_TYPES = new Set(Object.keys(DEFAULT_INSTRUCTIONS_PATH_KEYS));
|
||||
|
||||
/** Check if an adapter supports the managed instructions bundle. */
|
||||
function adapterSupportsInstructionsBundle(adapterType: string): boolean {
|
||||
const adapter = findActiveServerAdapter(adapterType);
|
||||
if (adapter?.supportsInstructionsBundle !== undefined) return adapter.supportsInstructionsBundle;
|
||||
return DEFAULT_MANAGED_INSTRUCTIONS_ADAPTER_TYPES.has(adapterType);
|
||||
}
|
||||
|
||||
/** Resolve the adapter config key for the instructions file path. */
|
||||
function resolveInstructionsPathKey(adapterType: string): string | null {
|
||||
const adapter = findActiveServerAdapter(adapterType);
|
||||
if (adapter?.instructionsPathKey) return adapter.instructionsPathKey;
|
||||
return DEFAULT_INSTRUCTIONS_PATH_KEYS[adapterType] ?? null;
|
||||
}
|
||||
const KNOWN_INSTRUCTIONS_PATH_KEYS = new Set(["instructionsFilePath", "agentsMdPath"]);
|
||||
const KNOWN_INSTRUCTIONS_BUNDLE_KEYS = [
|
||||
"instructionsBundleMode",
|
||||
@@ -557,7 +573,7 @@ export function agentRoutes(db: Db) {
|
||||
adapterType: string;
|
||||
adapterConfig: unknown;
|
||||
}>(agent: T): Promise<T> {
|
||||
if (!DEFAULT_MANAGED_INSTRUCTIONS_ADAPTER_TYPES.has(agent.adapterType)) {
|
||||
if (!adapterSupportsInstructionsBundle(agent.adapterType)) {
|
||||
return agent;
|
||||
}
|
||||
|
||||
@@ -638,7 +654,9 @@ export function agentRoutes(db: Db) {
|
||||
};
|
||||
}
|
||||
|
||||
const ADAPTERS_REQUIRING_MATERIALIZED_RUNTIME_SKILLS = new Set([
|
||||
// Legacy hardcoded set — used as fallback when adapter module does not
|
||||
// declare requiresMaterializedRuntimeSkills explicitly.
|
||||
const LEGACY_MATERIALIZED_SKILLS_SET = new Set([
|
||||
"cursor",
|
||||
"gemini_local",
|
||||
"opencode_local",
|
||||
@@ -646,7 +664,11 @@ export function agentRoutes(db: Db) {
|
||||
]);
|
||||
|
||||
function shouldMaterializeRuntimeSkillsForAdapter(adapterType: string) {
|
||||
return ADAPTERS_REQUIRING_MATERIALIZED_RUNTIME_SKILLS.has(adapterType);
|
||||
const adapter = findActiveServerAdapter(adapterType);
|
||||
if (adapter?.requiresMaterializedRuntimeSkills !== undefined) {
|
||||
return adapter.requiresMaterializedRuntimeSkills;
|
||||
}
|
||||
return LEGACY_MATERIALIZED_SKILLS_SET.has(adapterType);
|
||||
}
|
||||
|
||||
async function buildRuntimeSkillConfig(
|
||||
@@ -1609,7 +1631,7 @@ export function agentRoutes(db: Db) {
|
||||
|
||||
const existingAdapterConfig = asRecord(existing.adapterConfig) ?? {};
|
||||
const explicitKey = asNonEmptyString(req.body.adapterConfigKey);
|
||||
const defaultKey = DEFAULT_INSTRUCTIONS_PATH_KEYS[existing.adapterType] ?? null;
|
||||
const defaultKey = resolveInstructionsPathKey(existing.adapterType);
|
||||
const adapterConfigKey = explicitKey ?? defaultKey;
|
||||
if (!adapterConfigKey) {
|
||||
res.status(422).json({
|
||||
|
||||
Reference in New Issue
Block a user