Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/adapter-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ export interface ServerAdapterModule {
sessionManagement?: import("./session-compaction.js").AdapterSessionManagement;
supportsLocalAgentJwt?: boolean;
models?: AdapterModel[];
listModels?: () => Promise<AdapterModel[]>;
listModels?: (opts?: { command?: string }) => Promise<AdapterModel[]>;
agentConfigurationDoc?: string;
/**
* Optional lifecycle hook when an agent is approved/hired (join-request or hire_agent approval).
Expand Down
6 changes: 6 additions & 0 deletions packages/adapters/opencode-local/src/server/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe("openCode models", () => {
await expect(listOpenCodeModels()).resolves.toEqual([]);
});

it("uses command option when provided", async () => {
await expect(
listOpenCodeModels({ command: "__paperclip_missing_opencode_command__" }),
).resolves.toEqual([]);
});

it("rejects when model is missing", async () => {
await expect(
ensureOpenCodeModelConfiguredAndAvailable({ model: "" }),
Expand Down
4 changes: 2 additions & 2 deletions packages/adapters/opencode-local/src/server/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ export async function ensureOpenCodeModelConfiguredAndAvailable(input: {
return models;
}

export async function listOpenCodeModels(): Promise<AdapterModel[]> {
export async function listOpenCodeModels(opts?: { command?: string }): Promise<AdapterModel[]> {
try {
return await discoverOpenCodeModelsCached();
return await discoverOpenCodeModelsCached({ command: opts?.command });
} catch {
return [];
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/adapters/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ export function getServerAdapter(type: string): ServerAdapterModule {
return adapter;
}

export async function listAdapterModels(type: string): Promise<{ id: string; label: string }[]> {
export async function listAdapterModels(type: string, opts?: { command?: string }): Promise<{ id: string; label: string }[]> {
const adapter = adaptersByType.get(type);
if (!adapter) return [];
if (adapter.listModels) {
const discovered = await adapter.listModels();
const discovered = await adapter.listModels(opts);
if (discovered.length > 0) return discovered;
}
return adapter.models ?? [];
Expand Down
10 changes: 9 additions & 1 deletion server/src/routes/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,15 @@ export function agentRoutes(db: Db) {
const companyId = req.params.companyId as string;
assertCompanyAccess(req, companyId);
const type = req.params.type as string;
const models = await listAdapterModels(type);
const agentId = typeof req.query.agentId === "string" ? req.query.agentId : undefined;
let command: string | undefined;
if (agentId) {
const agent = await svc.getById(agentId);
if (agent && agent.companyId === companyId && agent.adapterConfig && typeof agent.adapterConfig.command === "string") {
command = agent.adapterConfig.command;
}
}
const models = await listAdapterModels(type, command ? { command } : undefined);
res.json(models);
});

Expand Down
Loading