mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Switch OpenCode to explicit static/local-aware model selection (#5117)
> **Stacked PR (part 4 of 7).** Depends on: - PR #5114 - PR #5115 - PR #5116 > Diff against `master` includes commits from earlier PRs in the stack — the new commit in this PR is the topmost one. ## Thinking Path > - Paperclip orchestrates AI agents for zero-human companies > - When creating an OpenCode-local agent, Paperclip currently validates > `adapterConfig.model` against the *Paperclip host's* `opencode models` output > - SSH testing surfaced that this blocks creating an OpenCode agent for an SSH > environment: the model that exists on the SSH target isn't visible to the > host, so creation fails with "OpenCode requires `adapterConfig.model` in > provider/model format" even when the operator picked a real remote model > - The initial direction was environment-aware model discovery; the final > decision was to keep OpenCode on the same explicit-model pattern as other > adapters (default + curated list + manual override) and stop blocking > creation on host-side discovery > - This PR does both: the adapter-models endpoint now accepts `environmentId` and > probes against the target environment, and the create-time hard gate is > replaced by `requireOpenCodeModelId` which validates `provider/model` *format* > without requiring host-local discovery. Test/run-time still surfaces real > auth/availability problems > - The benefit is that operators can create OpenCode agents for remote > environments without out-of-band setup, and the model picker in the UI > reflects the actually-targeted environment ## What Changed - Added `requireOpenCodeModelId(input)` in `opencode-local/src/server/models.ts`, exported it from the adapter index - `ensureOpenCodeModelConfiguredAndAvailable` now delegates the format check to `requireOpenCodeModelId` - `agentsApi.adapterModels(companyId, adapterType, { environmentId })` now accepts an environment ID and passes it as a query parameter - `queryKeys.agents.adapterModels` now keys on `(companyId, adapterType, environmentId)` - `server/src/routes/agents.ts` reads and validates the new query parameter, forwarding it to the adapter's model probe - `AgentConfigForm.tsx` and `OnboardingWizard.tsx` build the model query key from the currently selected default environment ID and disable autodetect for `opencode_local` (model selection is explicit) - `NewAgent.tsx` simplified — no longer special-cases OpenCode autodetect - `company-portability.ts` no longer needs OpenCode-specific autodetect handling - Tests added/updated: `adapter-model-refresh-routes.test.ts`, `adapter-models.test.ts`, `agent-permissions-routes.test.ts`, `opencode-local/src/server/models.test.ts` ## Verification - `pnpm --filter @paperclipai/server test -- adapter-models adapter-model-refresh agent-permissions` - `pnpm --filter @paperclipai/adapter-opencode-local test` - `pnpm --filter @paperclipai/ui test -- AgentConfigForm OnboardingWizard NewAgent` - Manual QA in browser: 1. Boot Paperclip on Tailscale-bound port (so it's reachable from another machine), create an OpenCode-local agent, switch the default environment between two installed sandboxes, and confirm the model list refreshes per-environment 2. Submit with a malformed `provider/model` string and verify the new `requireOpenCodeModelId` error surfaces - Before/after screenshots attached for `AgentConfigForm` model picker ## Risks - Behavioural shift: switching default environment now triggers a model refetch. Should be cheap but introduces a new UI loading state for OpenCode users. - Removing dynamic autodetect for OpenCode: if any user configured an agent without specifying `model` and relied on autodetect populating it, that agent will now fail at submit time. Mitigation: validation error is explicit and actionable. - New query string parameter on `/api/companies/:id/adapter-models` — older clients that omit it still work (parameter is optional and defaults to null). ## Model Used - OpenAI GPT-5.4 (reasoning effort: high) via Codex CLI - Provider: OpenAI - Used to author the code changes in this PR ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] If this change affects the UI, I have included before/after screenshots - [ ] I have updated relevant documentation to reflect my changes — N/A - [x] I have considered and documented any risks above - [x] I will address all Greptile and reviewer comments before requesting merge
This commit is contained in:
parent
076067865f
commit
bb7d040894
14 changed files with 281 additions and 139 deletions
|
|
@ -5,6 +5,13 @@ export const label = "OpenCode (local)";
|
||||||
|
|
||||||
export const DEFAULT_OPENCODE_LOCAL_MODEL = "openai/gpt-5.2-codex";
|
export const DEFAULT_OPENCODE_LOCAL_MODEL = "openai/gpt-5.2-codex";
|
||||||
|
|
||||||
|
export function isValidOpenCodeModelId(value: unknown): value is string {
|
||||||
|
if (typeof value !== "string") return false;
|
||||||
|
const trimmed = value.trim();
|
||||||
|
const slashIndex = trimmed.indexOf("/");
|
||||||
|
return Boolean(trimmed) && slashIndex > 0 && slashIndex !== trimmed.length - 1;
|
||||||
|
}
|
||||||
|
|
||||||
export const models: Array<{ id: string; label: string }> = [
|
export const models: Array<{ id: string; label: string }> = [
|
||||||
{ id: DEFAULT_OPENCODE_LOCAL_MODEL, label: DEFAULT_OPENCODE_LOCAL_MODEL },
|
{ id: DEFAULT_OPENCODE_LOCAL_MODEL, label: DEFAULT_OPENCODE_LOCAL_MODEL },
|
||||||
{ id: "openai/gpt-5.4", label: "openai/gpt-5.4" },
|
{ id: "openai/gpt-5.4", label: "openai/gpt-5.4" },
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ export {
|
||||||
listOpenCodeModels,
|
listOpenCodeModels,
|
||||||
discoverOpenCodeModels,
|
discoverOpenCodeModels,
|
||||||
ensureOpenCodeModelConfiguredAndAvailable,
|
ensureOpenCodeModelConfiguredAndAvailable,
|
||||||
|
requireOpenCodeModelId,
|
||||||
resetOpenCodeModelsCacheForTests,
|
resetOpenCodeModelsCacheForTests,
|
||||||
} from "./models.js";
|
} from "./models.js";
|
||||||
export { parseOpenCodeJsonl, isOpenCodeUnknownSessionError } from "./parse.js";
|
export { parseOpenCodeJsonl, isOpenCodeUnknownSessionError } from "./parse.js";
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { afterEach, describe, expect, it } from "vitest";
|
||||||
import {
|
import {
|
||||||
ensureOpenCodeModelConfiguredAndAvailable,
|
ensureOpenCodeModelConfiguredAndAvailable,
|
||||||
listOpenCodeModels,
|
listOpenCodeModels,
|
||||||
|
requireOpenCodeModelId,
|
||||||
resetOpenCodeModelsCacheForTests,
|
resetOpenCodeModelsCacheForTests,
|
||||||
} from "./models.js";
|
} from "./models.js";
|
||||||
|
|
||||||
|
|
@ -22,6 +23,19 @@ describe("openCode models", () => {
|
||||||
).rejects.toThrow("OpenCode requires `adapterConfig.model`");
|
).rejects.toThrow("OpenCode requires `adapterConfig.model`");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("accepts a provider/model id without running discovery", () => {
|
||||||
|
expect(requireOpenCodeModelId("openai/gpt-5.2-codex")).toBe("openai/gpt-5.2-codex");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("rejects malformed provider/model ids before discovery", () => {
|
||||||
|
expect(() => requireOpenCodeModelId("gpt-5.2-codex")).toThrow(
|
||||||
|
"OpenCode requires `adapterConfig.model`",
|
||||||
|
);
|
||||||
|
expect(() => requireOpenCodeModelId("openai/")).toThrow(
|
||||||
|
"OpenCode requires `adapterConfig.model`",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("rejects when discovery cannot run for configured model", async () => {
|
it("rejects when discovery cannot run for configured model", async () => {
|
||||||
process.env.PAPERCLIP_OPENCODE_COMMAND = "__paperclip_missing_opencode_command__";
|
process.env.PAPERCLIP_OPENCODE_COMMAND = "__paperclip_missing_opencode_command__";
|
||||||
await expect(
|
await expect(
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import {
|
||||||
ensurePathInEnv,
|
ensurePathInEnv,
|
||||||
runChildProcess,
|
runChildProcess,
|
||||||
} from "@paperclipai/adapter-utils/server-utils";
|
} from "@paperclipai/adapter-utils/server-utils";
|
||||||
|
import { isValidOpenCodeModelId } from "../index.js";
|
||||||
|
|
||||||
const MODELS_CACHE_TTL_MS = 60_000;
|
const MODELS_CACHE_TTL_MS = 60_000;
|
||||||
const MODELS_DISCOVERY_TIMEOUT_MS = 20_000;
|
const MODELS_DISCOVERY_TIMEOUT_MS = 20_000;
|
||||||
|
|
@ -23,6 +24,14 @@ const discoveryCache = new Map<string, { expiresAt: number; models: AdapterModel
|
||||||
const VOLATILE_ENV_KEY_PREFIXES = ["PAPERCLIP_", "npm_", "NPM_"] as const;
|
const VOLATILE_ENV_KEY_PREFIXES = ["PAPERCLIP_", "npm_", "NPM_"] as const;
|
||||||
const VOLATILE_ENV_KEY_EXACT = new Set(["PWD", "OLDPWD", "SHLVL", "_", "TERM_SESSION_ID", "HOME"]);
|
const VOLATILE_ENV_KEY_EXACT = new Set(["PWD", "OLDPWD", "SHLVL", "_", "TERM_SESSION_ID", "HOME"]);
|
||||||
|
|
||||||
|
export function requireOpenCodeModelId(input: unknown): string {
|
||||||
|
const model = asString(input, "").trim();
|
||||||
|
if (!isValidOpenCodeModelId(model)) {
|
||||||
|
throw new Error("OpenCode requires `adapterConfig.model` in provider/model format.");
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
function dedupeModels(models: AdapterModel[]): AdapterModel[] {
|
function dedupeModels(models: AdapterModel[]): AdapterModel[] {
|
||||||
const seen = new Set<string>();
|
const seen = new Set<string>();
|
||||||
const deduped: AdapterModel[] = [];
|
const deduped: AdapterModel[] = [];
|
||||||
|
|
@ -172,10 +181,7 @@ export async function ensureOpenCodeModelConfiguredAndAvailable(input: {
|
||||||
cwd?: unknown;
|
cwd?: unknown;
|
||||||
env?: unknown;
|
env?: unknown;
|
||||||
}): Promise<AdapterModel[]> {
|
}): Promise<AdapterModel[]> {
|
||||||
const model = asString(input.model, "").trim();
|
const model = requireOpenCodeModelId(input.model);
|
||||||
if (!model) {
|
|
||||||
throw new Error("OpenCode requires `adapterConfig.model` in provider/model format.");
|
|
||||||
}
|
|
||||||
|
|
||||||
const models = await discoverOpenCodeModelsCached({
|
const models = await discoverOpenCodeModelsCached({
|
||||||
command: input.command,
|
command: input.command,
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,16 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import request from "supertest";
|
import request from "supertest";
|
||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { models as openCodeFallbackModels } from "@paperclipai/adapter-opencode-local";
|
||||||
import type { ServerAdapterModule } from "../adapters/index.js";
|
import type { ServerAdapterModule } from "../adapters/index.js";
|
||||||
|
|
||||||
|
vi.mock("acpx/runtime", () => ({
|
||||||
|
createAcpRuntime: vi.fn(),
|
||||||
|
createAgentRegistry: vi.fn(),
|
||||||
|
createRuntimeStore: vi.fn(),
|
||||||
|
isAcpRuntimeError: vi.fn(() => false),
|
||||||
|
}));
|
||||||
|
|
||||||
const mockAccessService = vi.hoisted(() => ({
|
const mockAccessService = vi.hoisted(() => ({
|
||||||
canUser: vi.fn(),
|
canUser: vi.fn(),
|
||||||
hasPermission: vi.fn(),
|
hasPermission: vi.fn(),
|
||||||
|
|
@ -19,6 +27,10 @@ const mockSecretService = vi.hoisted(() => ({
|
||||||
normalizeAdapterConfigForPersistence: vi.fn(async (_companyId: string, config: Record<string, unknown>) => config),
|
normalizeAdapterConfigForPersistence: vi.fn(async (_companyId: string, config: Record<string, unknown>) => config),
|
||||||
resolveAdapterConfigForRuntime: vi.fn(async (_companyId: string, config: Record<string, unknown>) => ({ config })),
|
resolveAdapterConfigForRuntime: vi.fn(async (_companyId: string, config: Record<string, unknown>) => ({ config })),
|
||||||
}));
|
}));
|
||||||
|
const mockEnvironmentService = vi.hoisted(() => ({
|
||||||
|
getById: vi.fn(),
|
||||||
|
}));
|
||||||
|
const mockListOpenCodeModels = vi.hoisted(() => vi.fn());
|
||||||
|
|
||||||
const mockAgentInstructionsService = vi.hoisted(() => ({
|
const mockAgentInstructionsService = vi.hoisted(() => ({
|
||||||
materializeManagedBundle: vi.fn(),
|
materializeManagedBundle: vi.fn(),
|
||||||
|
|
@ -55,6 +67,14 @@ const mockInstanceSettingsService = vi.hoisted(() => ({
|
||||||
const mockLogActivity = vi.hoisted(() => vi.fn());
|
const mockLogActivity = vi.hoisted(() => vi.fn());
|
||||||
|
|
||||||
function registerModuleMocks() {
|
function registerModuleMocks() {
|
||||||
|
vi.doMock("@paperclipai/adapter-opencode-local/server", async () => {
|
||||||
|
const actual = await vi.importActual<typeof import("@paperclipai/adapter-opencode-local/server")>("@paperclipai/adapter-opencode-local/server");
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
listOpenCodeModels: mockListOpenCodeModels,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
vi.doMock("../services/index.js", () => ({
|
vi.doMock("../services/index.js", () => ({
|
||||||
agentService: () => ({}),
|
agentService: () => ({}),
|
||||||
agentInstructionsService: () => mockAgentInstructionsService,
|
agentInstructionsService: () => mockAgentInstructionsService,
|
||||||
|
|
@ -74,6 +94,10 @@ function registerModuleMocks() {
|
||||||
vi.doMock("../services/instance-settings.js", () => ({
|
vi.doMock("../services/instance-settings.js", () => ({
|
||||||
instanceSettingsService: () => mockInstanceSettingsService,
|
instanceSettingsService: () => mockInstanceSettingsService,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.doMock("../services/environments.js", () => ({
|
||||||
|
environmentService: () => mockEnvironmentService,
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshableAdapterType = "refreshable_adapter_route_test";
|
const refreshableAdapterType = "refreshable_adapter_route_test";
|
||||||
|
|
@ -147,6 +171,10 @@ describe("adapter model refresh route", () => {
|
||||||
mockAccessService.ensureMembership.mockResolvedValue(undefined);
|
mockAccessService.ensureMembership.mockResolvedValue(undefined);
|
||||||
mockAccessService.setPrincipalPermission.mockResolvedValue(undefined);
|
mockAccessService.setPrincipalPermission.mockResolvedValue(undefined);
|
||||||
mockLogActivity.mockResolvedValue(undefined);
|
mockLogActivity.mockResolvedValue(undefined);
|
||||||
|
mockEnvironmentService.getById.mockReset();
|
||||||
|
mockEnvironmentService.getById.mockResolvedValue(null);
|
||||||
|
mockListOpenCodeModels.mockReset();
|
||||||
|
mockListOpenCodeModels.mockResolvedValue([{ id: "dynamic-opencode-model", label: "dynamic-opencode-model" }]);
|
||||||
await unregisterTestAdapter(refreshableAdapterType);
|
await unregisterTestAdapter(refreshableAdapterType);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -182,4 +210,42 @@ describe("adapter model refresh route", () => {
|
||||||
expect(refreshModels).toHaveBeenCalledTimes(1);
|
expect(refreshModels).toHaveBeenCalledTimes(1);
|
||||||
expect(listModels).not.toHaveBeenCalled();
|
expect(listModels).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("skips OpenCode model discovery for non-local environments", async () => {
|
||||||
|
mockEnvironmentService.getById.mockResolvedValue({
|
||||||
|
id: "env-1",
|
||||||
|
companyId: "company-1",
|
||||||
|
name: "Remote SSH",
|
||||||
|
driver: "ssh",
|
||||||
|
config: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = await createApp();
|
||||||
|
const res = await requestApp(app, (baseUrl) =>
|
||||||
|
request(baseUrl).get("/api/companies/company-1/adapters/opencode_local/models?environmentId=env-1"),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(res.status, JSON.stringify(res.body)).toBe(200);
|
||||||
|
expect(res.body).toEqual(openCodeFallbackModels);
|
||||||
|
expect(mockListOpenCodeModels).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("keeps OpenCode model discovery enabled for local environments", async () => {
|
||||||
|
mockEnvironmentService.getById.mockResolvedValue({
|
||||||
|
id: "env-1",
|
||||||
|
companyId: "company-1",
|
||||||
|
name: "Local",
|
||||||
|
driver: "local",
|
||||||
|
config: {},
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = await createApp();
|
||||||
|
const res = await requestApp(app, (baseUrl) =>
|
||||||
|
request(baseUrl).get("/api/companies/company-1/adapters/opencode_local/models?environmentId=env-1"),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(res.status, JSON.stringify(res.body)).toBe(200);
|
||||||
|
expect(res.body).toEqual([{ id: "dynamic-opencode-model", label: "dynamic-opencode-model" }]);
|
||||||
|
expect(mockListOpenCodeModels).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,13 @@ import { listAdapterModels, refreshAdapterModels } from "../adapters/index.js";
|
||||||
import { resetCodexModelsCacheForTests } from "../adapters/codex-models.js";
|
import { resetCodexModelsCacheForTests } from "../adapters/codex-models.js";
|
||||||
import { resetCursorModelsCacheForTests, setCursorModelsRunnerForTests } from "../adapters/cursor-models.js";
|
import { resetCursorModelsCacheForTests, setCursorModelsRunnerForTests } from "../adapters/cursor-models.js";
|
||||||
|
|
||||||
|
vi.mock("acpx/runtime", () => ({
|
||||||
|
createAcpRuntime: vi.fn(),
|
||||||
|
createAgentRegistry: vi.fn(),
|
||||||
|
createRuntimeStore: vi.fn(),
|
||||||
|
isAcpRuntimeError: vi.fn(() => false),
|
||||||
|
}));
|
||||||
|
|
||||||
describe("adapter model listing", () => {
|
describe("adapter model listing", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
delete process.env.OPENAI_API_KEY;
|
delete process.env.OPENAI_API_KEY;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,14 @@
|
||||||
import express from "express";
|
import express from "express";
|
||||||
import request from "supertest";
|
import request from "supertest";
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import { DEFAULT_OPENCODE_LOCAL_MODEL } from "@paperclipai/adapter-opencode-local";
|
||||||
|
|
||||||
|
vi.mock("acpx/runtime", () => ({
|
||||||
|
createAcpRuntime: vi.fn(),
|
||||||
|
createAgentRegistry: vi.fn(),
|
||||||
|
createRuntimeStore: vi.fn(),
|
||||||
|
isAcpRuntimeError: vi.fn(() => false),
|
||||||
|
}));
|
||||||
|
|
||||||
const agentId = "11111111-1111-4111-8111-111111111111";
|
const agentId = "11111111-1111-4111-8111-111111111111";
|
||||||
const companyId = "22222222-2222-4222-8222-222222222222";
|
const companyId = "22222222-2222-4222-8222-222222222222";
|
||||||
|
|
@ -908,6 +916,78 @@ describe.sequential("agent permission routes", () => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("seeds opencode agent creation with the static default model without live discovery", async () => {
|
||||||
|
mockEnsureOpenCodeModelConfiguredAndAvailable.mockRejectedValue(
|
||||||
|
new Error("`opencode models` should not be called during creation"),
|
||||||
|
);
|
||||||
|
|
||||||
|
const app = await createApp({
|
||||||
|
type: "board",
|
||||||
|
userId: "board-user",
|
||||||
|
source: "local_implicit",
|
||||||
|
isInstanceAdmin: true,
|
||||||
|
companyIds: [companyId],
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await requestApp(app, (baseUrl) => request(baseUrl)
|
||||||
|
.post(`/api/companies/${companyId}/agents`)
|
||||||
|
.send({
|
||||||
|
name: "OpenCode Builder",
|
||||||
|
role: "engineer",
|
||||||
|
adapterType: "opencode_local",
|
||||||
|
adapterConfig: {},
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(res.status, JSON.stringify(res.body)).toBe(201);
|
||||||
|
expect(mockEnsureOpenCodeModelConfiguredAndAvailable).not.toHaveBeenCalled();
|
||||||
|
expect(mockAgentService.create).toHaveBeenCalledWith(
|
||||||
|
companyId,
|
||||||
|
expect.objectContaining({
|
||||||
|
adapterType: "opencode_local",
|
||||||
|
adapterConfig: expect.objectContaining({
|
||||||
|
model: DEFAULT_OPENCODE_LOCAL_MODEL,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("accepts manual opencode provider/model values without host-side discovery", async () => {
|
||||||
|
mockEnsureOpenCodeModelConfiguredAndAvailable.mockRejectedValue(
|
||||||
|
new Error("`opencode models` should not be called during creation"),
|
||||||
|
);
|
||||||
|
|
||||||
|
const app = await createApp({
|
||||||
|
type: "board",
|
||||||
|
userId: "board-user",
|
||||||
|
source: "local_implicit",
|
||||||
|
isInstanceAdmin: true,
|
||||||
|
companyIds: [companyId],
|
||||||
|
});
|
||||||
|
|
||||||
|
const res = await requestApp(app, (baseUrl) => request(baseUrl)
|
||||||
|
.post(`/api/companies/${companyId}/agents`)
|
||||||
|
.send({
|
||||||
|
name: "OpenCode Builder",
|
||||||
|
role: "engineer",
|
||||||
|
adapterType: "opencode_local",
|
||||||
|
adapterConfig: {
|
||||||
|
model: "anthropic/claude-sonnet-4-5",
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
expect(res.status, JSON.stringify(res.body)).toBe(201);
|
||||||
|
expect(mockEnsureOpenCodeModelConfiguredAndAvailable).not.toHaveBeenCalled();
|
||||||
|
expect(mockAgentService.create).toHaveBeenCalledWith(
|
||||||
|
companyId,
|
||||||
|
expect.objectContaining({
|
||||||
|
adapterType: "opencode_local",
|
||||||
|
adapterConfig: expect.objectContaining({
|
||||||
|
model: "anthropic/claude-sonnet-4-5",
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("normalizes hire requests to disable timer heartbeats by default", async () => {
|
it("normalizes hire requests to disable timer heartbeats by default", async () => {
|
||||||
const app = await createApp({
|
const app = await createApp({
|
||||||
type: "board",
|
type: "board",
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,8 @@ import {
|
||||||
} from "@paperclipai/adapter-codex-local";
|
} from "@paperclipai/adapter-codex-local";
|
||||||
import { DEFAULT_CURSOR_LOCAL_MODEL } from "@paperclipai/adapter-cursor-local";
|
import { DEFAULT_CURSOR_LOCAL_MODEL } from "@paperclipai/adapter-cursor-local";
|
||||||
import { DEFAULT_GEMINI_LOCAL_MODEL } from "@paperclipai/adapter-gemini-local";
|
import { DEFAULT_GEMINI_LOCAL_MODEL } from "@paperclipai/adapter-gemini-local";
|
||||||
import { ensureOpenCodeModelConfiguredAndAvailable } from "@paperclipai/adapter-opencode-local/server";
|
import { DEFAULT_OPENCODE_LOCAL_MODEL } from "@paperclipai/adapter-opencode-local";
|
||||||
|
import { requireOpenCodeModelId } from "@paperclipai/adapter-opencode-local/server";
|
||||||
import {
|
import {
|
||||||
loadDefaultAgentInstructionsBundle,
|
loadDefaultAgentInstructionsBundle,
|
||||||
resolveDefaultAgentInstructionsBundleRole,
|
resolveDefaultAgentInstructionsBundleRole,
|
||||||
|
|
@ -767,7 +768,6 @@ export function agentRoutes(
|
||||||
{ strictMode: strictSecretsMode },
|
{ strictMode: strictSecretsMode },
|
||||||
);
|
);
|
||||||
await assertAdapterConfigConstraints(
|
await assertAdapterConfigConstraints(
|
||||||
input.companyId,
|
|
||||||
input.adapterType,
|
input.adapterType,
|
||||||
input.constraintAdapterConfig
|
input.constraintAdapterConfig
|
||||||
? { ...input.constraintAdapterConfig, ...normalizedAdapterConfig }
|
? { ...input.constraintAdapterConfig, ...normalizedAdapterConfig }
|
||||||
|
|
@ -864,7 +864,10 @@ export function agentRoutes(
|
||||||
next.model = DEFAULT_GEMINI_LOCAL_MODEL;
|
next.model = DEFAULT_GEMINI_LOCAL_MODEL;
|
||||||
return ensureGatewayDeviceKey(adapterType, next);
|
return ensureGatewayDeviceKey(adapterType, next);
|
||||||
}
|
}
|
||||||
// OpenCode requires explicit model selection — no default
|
if (adapterType === "opencode_local" && !asNonEmptyString(next.model)) {
|
||||||
|
next.model = DEFAULT_OPENCODE_LOCAL_MODEL;
|
||||||
|
return ensureGatewayDeviceKey(adapterType, next);
|
||||||
|
}
|
||||||
if (adapterType === "cursor" && !asNonEmptyString(next.model)) {
|
if (adapterType === "cursor" && !asNonEmptyString(next.model)) {
|
||||||
next.model = DEFAULT_CURSOR_LOCAL_MODEL;
|
next.model = DEFAULT_CURSOR_LOCAL_MODEL;
|
||||||
}
|
}
|
||||||
|
|
@ -872,20 +875,12 @@ export function agentRoutes(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assertAdapterConfigConstraints(
|
async function assertAdapterConfigConstraints(
|
||||||
companyId: string,
|
|
||||||
adapterType: string | null | undefined,
|
adapterType: string | null | undefined,
|
||||||
adapterConfig: Record<string, unknown>,
|
adapterConfig: Record<string, unknown>,
|
||||||
) {
|
) {
|
||||||
if (adapterType !== "opencode_local") return;
|
if (adapterType !== "opencode_local") return;
|
||||||
const { config: runtimeConfig } = await secretsSvc.resolveAdapterConfigForRuntime(companyId, adapterConfig);
|
|
||||||
const runtimeEnv = asRecord(runtimeConfig.env) ?? {};
|
|
||||||
try {
|
try {
|
||||||
await ensureOpenCodeModelConfiguredAndAvailable({
|
requireOpenCodeModelId(adapterConfig.model);
|
||||||
model: runtimeConfig.model,
|
|
||||||
command: runtimeConfig.command,
|
|
||||||
cwd: runtimeConfig.cwd,
|
|
||||||
env: runtimeEnv,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const reason = err instanceof Error ? err.message : String(err);
|
const reason = err instanceof Error ? err.message : String(err);
|
||||||
throw unprocessable(`Invalid opencode_local adapterConfig: ${reason}`);
|
throw unprocessable(`Invalid opencode_local adapterConfig: ${reason}`);
|
||||||
|
|
@ -1194,6 +1189,17 @@ export function agentRoutes(
|
||||||
const refresh = typeof req.query.refresh === "string"
|
const refresh = typeof req.query.refresh === "string"
|
||||||
? ["1", "true", "yes"].includes(req.query.refresh.toLowerCase())
|
? ["1", "true", "yes"].includes(req.query.refresh.toLowerCase())
|
||||||
: false;
|
: false;
|
||||||
|
const environmentId = asNonEmptyString(req.query.environmentId);
|
||||||
|
const environment = environmentId ? await environmentsSvc.getById(environmentId) : null;
|
||||||
|
if (environmentId && (!environment || environment.companyId !== companyId)) {
|
||||||
|
res.status(404).json({ error: "Environment not found" });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type === "opencode_local" && environment && environment.driver !== "local") {
|
||||||
|
const adapter = requireServerAdapter(type);
|
||||||
|
res.json(adapter.models ?? []);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const models = refresh
|
const models = refresh
|
||||||
? await refreshAdapterModels(type)
|
? await refreshAdapterModels(type)
|
||||||
: await listAdapterModels(type);
|
: await listAdapterModels(type);
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ import {
|
||||||
readPaperclipSkillSyncPreference,
|
readPaperclipSkillSyncPreference,
|
||||||
writePaperclipSkillSyncPreference,
|
writePaperclipSkillSyncPreference,
|
||||||
} from "@paperclipai/adapter-utils/server-utils";
|
} from "@paperclipai/adapter-utils/server-utils";
|
||||||
import { ensureOpenCodeModelConfiguredAndAvailable } from "@paperclipai/adapter-opencode-local/server";
|
import { requireOpenCodeModelId } from "@paperclipai/adapter-opencode-local/server";
|
||||||
import { findServerAdapter } from "../adapters/index.js";
|
import { findServerAdapter } from "../adapters/index.js";
|
||||||
import { forbidden, notFound, unprocessable } from "../errors.js";
|
import { forbidden, notFound, unprocessable } from "../errors.js";
|
||||||
import { ghFetch, gitHubApiBase, resolveRawGitHubUrl } from "./github-fetch.js";
|
import { ghFetch, gitHubApiBase, resolveRawGitHubUrl } from "./github-fetch.js";
|
||||||
|
|
@ -2781,20 +2781,12 @@ export function companyPortabilityService(db: Db, storage?: StorageService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assertImportAdapterConfigConstraints(
|
async function assertImportAdapterConfigConstraints(
|
||||||
companyId: string,
|
|
||||||
adapterType: string,
|
adapterType: string,
|
||||||
adapterConfig: Record<string, unknown>,
|
adapterConfig: Record<string, unknown>,
|
||||||
) {
|
) {
|
||||||
if (adapterType !== "opencode_local") return;
|
if (adapterType !== "opencode_local") return;
|
||||||
const { config: runtimeConfig } = await secrets.resolveAdapterConfigForRuntime(companyId, adapterConfig);
|
|
||||||
const runtimeEnv = isPlainRecord(runtimeConfig.env) ? runtimeConfig.env : {};
|
|
||||||
try {
|
try {
|
||||||
await ensureOpenCodeModelConfiguredAndAvailable({
|
requireOpenCodeModelId(adapterConfig.model);
|
||||||
model: runtimeConfig.model,
|
|
||||||
command: runtimeConfig.command,
|
|
||||||
cwd: runtimeConfig.cwd,
|
|
||||||
env: runtimeEnv,
|
|
||||||
});
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const reason = err instanceof Error ? err.message : String(err);
|
const reason = err instanceof Error ? err.message : String(err);
|
||||||
throw unprocessable(`Invalid opencode_local adapterConfig: ${reason}`);
|
throw unprocessable(`Invalid opencode_local adapterConfig: ${reason}`);
|
||||||
|
|
@ -2824,7 +2816,7 @@ export function companyPortabilityService(db: Db, storage?: StorageService) {
|
||||||
nextAdapterConfig,
|
nextAdapterConfig,
|
||||||
{ strictMode: strictSecretsMode },
|
{ strictMode: strictSecretsMode },
|
||||||
);
|
);
|
||||||
await assertImportAdapterConfigConstraints(companyId, effectiveAdapterType, normalizedAdapterConfig);
|
await assertImportAdapterConfigConstraints(effectiveAdapterType, normalizedAdapterConfig);
|
||||||
return {
|
return {
|
||||||
adapterType: effectiveAdapterType,
|
adapterType: effectiveAdapterType,
|
||||||
adapterConfig: normalizedAdapterConfig,
|
adapterConfig: normalizedAdapterConfig,
|
||||||
|
|
|
||||||
|
|
@ -171,10 +171,19 @@ export const agentsApi = {
|
||||||
api.get<AgentTaskSession[]>(agentPath(id, companyId, "/task-sessions")),
|
api.get<AgentTaskSession[]>(agentPath(id, companyId, "/task-sessions")),
|
||||||
resetSession: (id: string, taskKey?: string | null, companyId?: string) =>
|
resetSession: (id: string, taskKey?: string | null, companyId?: string) =>
|
||||||
api.post<void>(agentPath(id, companyId, "/runtime-state/reset-session"), { taskKey: taskKey ?? null }),
|
api.post<void>(agentPath(id, companyId, "/runtime-state/reset-session"), { taskKey: taskKey ?? null }),
|
||||||
adapterModels: (companyId: string, type: string, options?: { refresh?: boolean }) =>
|
adapterModels: (
|
||||||
api.get<AdapterModel[]>(
|
companyId: string,
|
||||||
`/companies/${encodeURIComponent(companyId)}/adapters/${encodeURIComponent(type)}/models${options?.refresh ? "?refresh=1" : ""}`,
|
type: string,
|
||||||
),
|
options?: { refresh?: boolean; environmentId?: string | null },
|
||||||
|
) => {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
if (options?.refresh) params.set("refresh", "1");
|
||||||
|
if (options?.environmentId) params.set("environmentId", options.environmentId);
|
||||||
|
const query = params.size > 0 ? `?${params.toString()}` : "";
|
||||||
|
return api.get<AdapterModel[]>(
|
||||||
|
`/companies/${encodeURIComponent(companyId)}/adapters/${encodeURIComponent(type)}/models${query}`,
|
||||||
|
);
|
||||||
|
},
|
||||||
detectModel: (companyId: string, type: string) =>
|
detectModel: (companyId: string, type: string) =>
|
||||||
api.get<DetectedAdapterModel | null>(
|
api.get<DetectedAdapterModel | null>(
|
||||||
`/companies/${encodeURIComponent(companyId)}/adapters/${encodeURIComponent(type)}/detect-model`,
|
`/companies/${encodeURIComponent(companyId)}/adapters/${encodeURIComponent(type)}/detect-model`,
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import {
|
||||||
} from "@paperclipai/adapter-codex-local";
|
} from "@paperclipai/adapter-codex-local";
|
||||||
import { DEFAULT_CURSOR_LOCAL_MODEL } from "@paperclipai/adapter-cursor-local";
|
import { DEFAULT_CURSOR_LOCAL_MODEL } from "@paperclipai/adapter-cursor-local";
|
||||||
import { DEFAULT_GEMINI_LOCAL_MODEL } from "@paperclipai/adapter-gemini-local";
|
import { DEFAULT_GEMINI_LOCAL_MODEL } from "@paperclipai/adapter-gemini-local";
|
||||||
|
import { DEFAULT_OPENCODE_LOCAL_MODEL } from "@paperclipai/adapter-opencode-local";
|
||||||
import {
|
import {
|
||||||
Popover,
|
Popover,
|
||||||
PopoverContent,
|
PopoverContent,
|
||||||
|
|
@ -322,6 +323,17 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
() => new Set(supportedEnvironmentDriversForAdapter(adapterType)),
|
() => new Set(supportedEnvironmentDriversForAdapter(adapterType)),
|
||||||
[adapterType],
|
[adapterType],
|
||||||
);
|
);
|
||||||
|
const val = isCreate ? props.values : null;
|
||||||
|
const set = isCreate
|
||||||
|
? (patch: Partial<CreateConfigValues>) => props.onChange(patch)
|
||||||
|
: null;
|
||||||
|
const currentDefaultEnvironmentId = isCreate
|
||||||
|
? val!.defaultEnvironmentId ?? ""
|
||||||
|
: eff("identity", "defaultEnvironmentId", props.agent.defaultEnvironmentId ?? "");
|
||||||
|
const currentDefaultEnvironment = useMemo(
|
||||||
|
() => environments.find((environment) => environment.id === currentDefaultEnvironmentId) ?? null,
|
||||||
|
[currentDefaultEnvironmentId, environments],
|
||||||
|
);
|
||||||
const runnableEnvironments = useMemo(
|
const runnableEnvironments = useMemo(
|
||||||
() => environments.filter((environment) => {
|
() => environments.filter((environment) => {
|
||||||
if (!supportedEnvironmentDrivers.has(environment.driver)) return false;
|
if (!supportedEnvironmentDrivers.has(environment.driver)) return false;
|
||||||
|
|
@ -334,14 +346,16 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
|
|
||||||
// Fetch adapter models for the effective adapter type
|
// Fetch adapter models for the effective adapter type
|
||||||
const modelQueryKey = selectedCompanyId
|
const modelQueryKey = selectedCompanyId
|
||||||
? queryKeys.agents.adapterModels(selectedCompanyId, adapterType)
|
? queryKeys.agents.adapterModels(selectedCompanyId, adapterType, currentDefaultEnvironmentId || null)
|
||||||
: ["agents", "none", "adapter-models", adapterType];
|
: ["agents", "none", "adapter-models", adapterType];
|
||||||
const {
|
const {
|
||||||
data: fetchedModels,
|
data: fetchedModels,
|
||||||
error: fetchedModelsError,
|
error: fetchedModelsError,
|
||||||
} = useQuery({
|
} = useQuery({
|
||||||
queryKey: modelQueryKey,
|
queryKey: modelQueryKey,
|
||||||
queryFn: () => agentsApi.adapterModels(selectedCompanyId!, adapterType),
|
queryFn: () => agentsApi.adapterModels(selectedCompanyId!, adapterType, {
|
||||||
|
environmentId: currentDefaultEnvironmentId || null,
|
||||||
|
}),
|
||||||
enabled: Boolean(selectedCompanyId),
|
enabled: Boolean(selectedCompanyId),
|
||||||
});
|
});
|
||||||
const [refreshModelsError, setRefreshModelsError] = useState<string | null>(null);
|
const [refreshModelsError, setRefreshModelsError] = useState<string | null>(null);
|
||||||
|
|
@ -362,7 +376,7 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
}
|
}
|
||||||
return agentsApi.detectModel(selectedCompanyId, adapterType);
|
return agentsApi.detectModel(selectedCompanyId, adapterType);
|
||||||
},
|
},
|
||||||
enabled: Boolean(selectedCompanyId && isLocal),
|
enabled: Boolean(selectedCompanyId && isLocal && adapterType !== "opencode_local"),
|
||||||
});
|
});
|
||||||
const detectedModel = detectedModelData?.model ?? null;
|
const detectedModel = detectedModelData?.model ?? null;
|
||||||
const detectedModelCandidates = detectedModelData?.candidates ?? [];
|
const detectedModelCandidates = detectedModelData?.candidates ?? [];
|
||||||
|
|
@ -415,12 +429,6 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
return typeof value === "string" ? value : "";
|
return typeof value === "string" ? value : "";
|
||||||
}, [adapterCheapDefault]);
|
}, [adapterCheapDefault]);
|
||||||
|
|
||||||
// Create mode helpers
|
|
||||||
const val = isCreate ? props.values : null;
|
|
||||||
const set = isCreate
|
|
||||||
? (patch: Partial<CreateConfigValues>) => props.onChange(patch)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
function buildAdapterConfigForTest(): Record<string, unknown> {
|
function buildAdapterConfigForTest(): Record<string, unknown> {
|
||||||
if (isCreate) {
|
if (isCreate) {
|
||||||
return uiAdapter.buildAdapterConfig(val!);
|
return uiAdapter.buildAdapterConfig(val!);
|
||||||
|
|
@ -446,15 +454,9 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
if (!selectedCompanyId) {
|
if (!selectedCompanyId) {
|
||||||
throw new Error("Select a company to test adapter environment");
|
throw new Error("Select a company to test adapter environment");
|
||||||
}
|
}
|
||||||
const selectedEnvironmentId = isCreate
|
|
||||||
? val!.defaultEnvironmentId ?? null
|
|
||||||
: eff("identity", "defaultEnvironmentId", props.agent.defaultEnvironmentId ?? null);
|
|
||||||
return agentsApi.testEnvironment(selectedCompanyId, adapterType, {
|
return agentsApi.testEnvironment(selectedCompanyId, adapterType, {
|
||||||
adapterConfig: buildAdapterConfigForTest(),
|
adapterConfig: buildAdapterConfigForTest(),
|
||||||
environmentId:
|
environmentId: currentDefaultEnvironmentId || null,
|
||||||
typeof selectedEnvironmentId === "string" && selectedEnvironmentId.length > 0
|
|
||||||
? selectedEnvironmentId
|
|
||||||
: null,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
@ -638,9 +640,6 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
heartbeat: mergedHeartbeat,
|
heartbeat: mergedHeartbeat,
|
||||||
};
|
};
|
||||||
}, [isCreate, overlay.heartbeat, runtimeConfig, val]);
|
}, [isCreate, overlay.heartbeat, runtimeConfig, val]);
|
||||||
const currentDefaultEnvironmentId = isCreate
|
|
||||||
? val!.defaultEnvironmentId ?? ""
|
|
||||||
: eff("identity", "defaultEnvironmentId", props.agent.defaultEnvironmentId ?? "");
|
|
||||||
const effectiveHeartbeat = asObject(effectiveRuntimeConfig.heartbeat);
|
const effectiveHeartbeat = asObject(effectiveRuntimeConfig.heartbeat);
|
||||||
const maxTurnContinuation = asObject(effectiveHeartbeat.maxTurnContinuation);
|
const maxTurnContinuation = asObject(effectiveHeartbeat.maxTurnContinuation);
|
||||||
const maxTurnContinuationEnabled = asBoolean(maxTurnContinuation.enabled, true);
|
const maxTurnContinuationEnabled = asBoolean(maxTurnContinuation.enabled, true);
|
||||||
|
|
@ -834,7 +833,7 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
} else if (t === "cursor") {
|
} else if (t === "cursor") {
|
||||||
nextValues.model = DEFAULT_CURSOR_LOCAL_MODEL;
|
nextValues.model = DEFAULT_CURSOR_LOCAL_MODEL;
|
||||||
} else if (t === "opencode_local") {
|
} else if (t === "opencode_local") {
|
||||||
nextValues.model = "";
|
nextValues.model = DEFAULT_OPENCODE_LOCAL_MODEL;
|
||||||
}
|
}
|
||||||
set!(nextValues);
|
set!(nextValues);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -850,9 +849,11 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
? DEFAULT_CODEX_LOCAL_MODEL
|
? DEFAULT_CODEX_LOCAL_MODEL
|
||||||
: t === "gemini_local"
|
: t === "gemini_local"
|
||||||
? DEFAULT_GEMINI_LOCAL_MODEL
|
? DEFAULT_GEMINI_LOCAL_MODEL
|
||||||
|
: t === "opencode_local"
|
||||||
|
? DEFAULT_OPENCODE_LOCAL_MODEL
|
||||||
: t === "cursor"
|
: t === "cursor"
|
||||||
? DEFAULT_CURSOR_LOCAL_MODEL
|
? DEFAULT_CURSOR_LOCAL_MODEL
|
||||||
: "",
|
: "",
|
||||||
effort: "",
|
effort: "",
|
||||||
modelReasoningEffort: "",
|
modelReasoningEffort: "",
|
||||||
variant: "",
|
variant: "",
|
||||||
|
|
@ -975,10 +976,12 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
creatable
|
creatable
|
||||||
detectedModel={detectedModel}
|
detectedModel={detectedModel}
|
||||||
detectedModelCandidates={[]}
|
detectedModelCandidates={[]}
|
||||||
onDetectModel={async () => {
|
onDetectModel={adapterType === "opencode_local"
|
||||||
const result = await refetchDetectedModel();
|
? undefined
|
||||||
return result.data?.model ?? null;
|
: async () => {
|
||||||
}}
|
const result = await refetchDetectedModel();
|
||||||
|
return result.data?.model ?? null;
|
||||||
|
}}
|
||||||
onRefreshModels={adapterType === "codex_local" ? handleRefreshModels : undefined}
|
onRefreshModels={adapterType === "codex_local" ? handleRefreshModels : undefined}
|
||||||
refreshingModels={refreshingModels}
|
refreshingModels={refreshingModels}
|
||||||
detectModelLabel="Detect model"
|
detectModelLabel="Detect model"
|
||||||
|
|
@ -992,6 +995,13 @@ export function AgentConfigForm(props: AgentConfigFormProps) {
|
||||||
: "Failed to load adapter models.")}
|
: "Failed to load adapter models.")}
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
{adapterType === "opencode_local"
|
||||||
|
&& currentDefaultEnvironment
|
||||||
|
&& currentDefaultEnvironment.driver !== "local" && (
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
Live OpenCode model discovery only runs for Local environments. Using the curated list and manual entry for {currentDefaultEnvironment.name}.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
|
||||||
{supportsModelProfiles && (
|
{supportsModelProfiles && (
|
||||||
<CheapModelSection
|
<CheapModelSection
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ import {
|
||||||
} from "@paperclipai/adapter-codex-local";
|
} from "@paperclipai/adapter-codex-local";
|
||||||
import { DEFAULT_CURSOR_LOCAL_MODEL } from "@paperclipai/adapter-cursor-local";
|
import { DEFAULT_CURSOR_LOCAL_MODEL } from "@paperclipai/adapter-cursor-local";
|
||||||
import { DEFAULT_GEMINI_LOCAL_MODEL } from "@paperclipai/adapter-gemini-local";
|
import { DEFAULT_GEMINI_LOCAL_MODEL } from "@paperclipai/adapter-gemini-local";
|
||||||
|
import { DEFAULT_OPENCODE_LOCAL_MODEL, isValidOpenCodeModelId } from "@paperclipai/adapter-opencode-local";
|
||||||
import { resolveRouteOnboardingOptions } from "../lib/onboarding-route";
|
import { resolveRouteOnboardingOptions } from "../lib/onboarding-route";
|
||||||
import { AsciiArtAnimation } from "./AsciiArtAnimation";
|
import { AsciiArtAnimation } from "./AsciiArtAnimation";
|
||||||
import {
|
import {
|
||||||
|
|
@ -189,16 +190,13 @@ export function OnboardingWizard() {
|
||||||
if (step === 3) autoResizeTextarea();
|
if (step === 3) autoResizeTextarea();
|
||||||
}, [step, taskDescription, autoResizeTextarea]);
|
}, [step, taskDescription, autoResizeTextarea]);
|
||||||
|
|
||||||
const {
|
const { data: adapterModels } = useQuery({
|
||||||
data: adapterModels,
|
// The wizard doesn't expose an environment selector, so models always
|
||||||
error: adapterModelsError,
|
// resolve against the local Paperclip host (environmentId = null).
|
||||||
isLoading: adapterModelsLoading,
|
|
||||||
isFetching: adapterModelsFetching
|
|
||||||
} = useQuery({
|
|
||||||
queryKey: createdCompanyId
|
queryKey: createdCompanyId
|
||||||
? queryKeys.agents.adapterModels(createdCompanyId, adapterType)
|
? queryKeys.agents.adapterModels(createdCompanyId, adapterType, null)
|
||||||
: ["agents", "none", "adapter-models", adapterType],
|
: ["agents", "none", "adapter-models", adapterType, null],
|
||||||
queryFn: () => agentsApi.adapterModels(createdCompanyId!, adapterType),
|
queryFn: () => agentsApi.adapterModels(createdCompanyId!, adapterType, { environmentId: null }),
|
||||||
enabled: Boolean(createdCompanyId) && effectiveOnboardingOpen && step === 2
|
enabled: Boolean(createdCompanyId) && effectiveOnboardingOpen && step === 2
|
||||||
});
|
});
|
||||||
const getCapabilities = useAdapterCapabilities();
|
const getCapabilities = useAdapterCapabilities();
|
||||||
|
|
@ -329,8 +327,10 @@ export function OnboardingWizard() {
|
||||||
: adapterType === "gemini_local"
|
: adapterType === "gemini_local"
|
||||||
? model || DEFAULT_GEMINI_LOCAL_MODEL
|
? model || DEFAULT_GEMINI_LOCAL_MODEL
|
||||||
: adapterType === "cursor"
|
: adapterType === "cursor"
|
||||||
? model || DEFAULT_CURSOR_LOCAL_MODEL
|
? model || DEFAULT_CURSOR_LOCAL_MODEL
|
||||||
: model,
|
: adapterType === "opencode_local"
|
||||||
|
? model || DEFAULT_OPENCODE_LOCAL_MODEL
|
||||||
|
: model,
|
||||||
command,
|
command,
|
||||||
args,
|
args,
|
||||||
url,
|
url,
|
||||||
|
|
@ -427,36 +427,12 @@ export function OnboardingWizard() {
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
if (adapterType === "opencode_local") {
|
if (adapterType === "opencode_local") {
|
||||||
const selectedModelId = model.trim();
|
if (!isValidOpenCodeModelId(model)) {
|
||||||
if (!selectedModelId) {
|
|
||||||
setError(
|
setError(
|
||||||
"OpenCode requires an explicit model in provider/model format."
|
"OpenCode requires an explicit model in provider/model format."
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (adapterModelsError) {
|
|
||||||
setError(
|
|
||||||
adapterModelsError instanceof Error
|
|
||||||
? adapterModelsError.message
|
|
||||||
: "Failed to load OpenCode models."
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (adapterModelsLoading || adapterModelsFetching) {
|
|
||||||
setError(
|
|
||||||
"OpenCode models are still loading. Please wait and try again."
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const discoveredModels = adapterModels ?? [];
|
|
||||||
if (!discoveredModels.some((entry) => entry.id === selectedModelId)) {
|
|
||||||
setError(
|
|
||||||
discoveredModels.length === 0
|
|
||||||
? "No OpenCode models discovered. Run `opencode models` and authenticate providers."
|
|
||||||
: `Configured OpenCode model is unavailable: ${selectedModelId}`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLocalAdapter) {
|
if (isLocalAdapter) {
|
||||||
|
|
@ -777,12 +753,17 @@ export function OnboardingWizard() {
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const nextType = opt.type;
|
const nextType = opt.type;
|
||||||
setAdapterType(nextType);
|
setAdapterType(nextType);
|
||||||
if (nextType === "codex_local" && !model) {
|
if (nextType === "codex_local") {
|
||||||
setModel(DEFAULT_CODEX_LOCAL_MODEL);
|
if (!model) {
|
||||||
|
setModel(DEFAULT_CODEX_LOCAL_MODEL);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (nextType !== "codex_local") {
|
if (nextType === "opencode_local") {
|
||||||
setModel("");
|
setModel(DEFAULT_OPENCODE_LOCAL_MODEL);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
setModel("");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{opt.recommended && (
|
{opt.recommended && (
|
||||||
|
|
@ -839,9 +820,7 @@ export function OnboardingWizard() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (nextType === "opencode_local") {
|
if (nextType === "opencode_local") {
|
||||||
if (!model.includes("/")) {
|
setModel(DEFAULT_OPENCODE_LOCAL_MODEL);
|
||||||
setModel("");
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setModel("");
|
setModel("");
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ export const queryKeys = {
|
||||||
["agents", "instructions-bundle", id, "file", relativePath] as const,
|
["agents", "instructions-bundle", id, "file", relativePath] as const,
|
||||||
keys: (agentId: string) => ["agents", "keys", agentId] as const,
|
keys: (agentId: string) => ["agents", "keys", agentId] as const,
|
||||||
configRevisions: (agentId: string) => ["agents", "config-revisions", agentId] as const,
|
configRevisions: (agentId: string) => ["agents", "config-revisions", agentId] as const,
|
||||||
adapterModels: (companyId: string, adapterType: string) =>
|
adapterModels: (companyId: string, adapterType: string, environmentId?: string | null) =>
|
||||||
["agents", companyId, "adapter-models", adapterType] as const,
|
["agents", companyId, "adapter-models", adapterType, environmentId ?? null] as const,
|
||||||
adapterModelProfiles: (companyId: string, adapterType: string) =>
|
adapterModelProfiles: (companyId: string, adapterType: string) =>
|
||||||
["agents", companyId, "adapter-model-profiles", adapterType] as const,
|
["agents", companyId, "adapter-model-profiles", adapterType] as const,
|
||||||
detectModel: (companyId: string, adapterType: string) =>
|
detectModel: (companyId: string, adapterType: string) =>
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ import {
|
||||||
} from "@paperclipai/adapter-codex-local";
|
} from "@paperclipai/adapter-codex-local";
|
||||||
import { DEFAULT_CURSOR_LOCAL_MODEL } from "@paperclipai/adapter-cursor-local";
|
import { DEFAULT_CURSOR_LOCAL_MODEL } from "@paperclipai/adapter-cursor-local";
|
||||||
import { DEFAULT_GEMINI_LOCAL_MODEL } from "@paperclipai/adapter-gemini-local";
|
import { DEFAULT_GEMINI_LOCAL_MODEL } from "@paperclipai/adapter-gemini-local";
|
||||||
|
import { DEFAULT_OPENCODE_LOCAL_MODEL, isValidOpenCodeModelId } from "@paperclipai/adapter-opencode-local";
|
||||||
|
|
||||||
function createValuesForAdapterType(
|
function createValuesForAdapterType(
|
||||||
adapterType: CreateConfigValues["adapterType"],
|
adapterType: CreateConfigValues["adapterType"],
|
||||||
|
|
@ -49,7 +50,7 @@ function createValuesForAdapterType(
|
||||||
} else if (adapterType === "cursor") {
|
} else if (adapterType === "cursor") {
|
||||||
nextValues.model = DEFAULT_CURSOR_LOCAL_MODEL;
|
nextValues.model = DEFAULT_CURSOR_LOCAL_MODEL;
|
||||||
} else if (adapterType === "opencode_local") {
|
} else if (adapterType === "opencode_local") {
|
||||||
nextValues.model = "";
|
nextValues.model = DEFAULT_OPENCODE_LOCAL_MODEL;
|
||||||
}
|
}
|
||||||
return nextValues;
|
return nextValues;
|
||||||
}
|
}
|
||||||
|
|
@ -86,19 +87,6 @@ export function NewAgent() {
|
||||||
enabled: !!selectedCompanyId,
|
enabled: !!selectedCompanyId,
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
|
||||||
data: adapterModels,
|
|
||||||
error: adapterModelsError,
|
|
||||||
isLoading: adapterModelsLoading,
|
|
||||||
isFetching: adapterModelsFetching,
|
|
||||||
} = useQuery({
|
|
||||||
queryKey: selectedCompanyId
|
|
||||||
? queryKeys.agents.adapterModels(selectedCompanyId, configValues.adapterType)
|
|
||||||
: ["agents", "none", "adapter-models", configValues.adapterType],
|
|
||||||
queryFn: () => agentsApi.adapterModels(selectedCompanyId!, configValues.adapterType),
|
|
||||||
enabled: Boolean(selectedCompanyId),
|
|
||||||
});
|
|
||||||
|
|
||||||
const { data: companySkills } = useQuery({
|
const { data: companySkills } = useQuery({
|
||||||
queryKey: queryKeys.companySkills.list(selectedCompanyId ?? ""),
|
queryKey: queryKeys.companySkills.list(selectedCompanyId ?? ""),
|
||||||
queryFn: () => companySkillsApi.list(selectedCompanyId!),
|
queryFn: () => companySkillsApi.list(selectedCompanyId!),
|
||||||
|
|
@ -154,32 +142,10 @@ export function NewAgent() {
|
||||||
if (!selectedCompanyId || !name.trim()) return;
|
if (!selectedCompanyId || !name.trim()) return;
|
||||||
setFormError(null);
|
setFormError(null);
|
||||||
if (configValues.adapterType === "opencode_local") {
|
if (configValues.adapterType === "opencode_local") {
|
||||||
const selectedModel = configValues.model.trim();
|
if (!isValidOpenCodeModelId(configValues.model)) {
|
||||||
if (!selectedModel) {
|
|
||||||
setFormError("OpenCode requires an explicit model in provider/model format.");
|
setFormError("OpenCode requires an explicit model in provider/model format.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (adapterModelsError) {
|
|
||||||
setFormError(
|
|
||||||
adapterModelsError instanceof Error
|
|
||||||
? adapterModelsError.message
|
|
||||||
: "Failed to load OpenCode models.",
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (adapterModelsLoading || adapterModelsFetching) {
|
|
||||||
setFormError("OpenCode models are still loading. Please wait and try again.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const discovered = adapterModels ?? [];
|
|
||||||
if (!discovered.some((entry) => entry.id === selectedModel)) {
|
|
||||||
setFormError(
|
|
||||||
discovered.length === 0
|
|
||||||
? "No OpenCode models discovered. Run `opencode models` and authenticate providers."
|
|
||||||
: `Configured OpenCode model is unavailable: ${selectedModel}`,
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
createAgent.mutate(
|
createAgent.mutate(
|
||||||
buildNewAgentHirePayload({
|
buildNewAgentHirePayload({
|
||||||
|
|
@ -295,7 +261,6 @@ export function NewAgent() {
|
||||||
mode="create"
|
mode="create"
|
||||||
values={configValues}
|
values={configValues}
|
||||||
onChange={(patch) => setConfigValues((prev) => ({ ...prev, ...patch }))}
|
onChange={(patch) => setConfigValues((prev) => ({ ...prev, ...patch }))}
|
||||||
adapterModels={adapterModels}
|
|
||||||
onTestActionChange={handleTestAgentActionChange}
|
onTestActionChange={handleTestAgentActionChange}
|
||||||
onTestActionStateChange={handleTestAgentStateChange}
|
onTestActionStateChange={handleTestAgentStateChange}
|
||||||
onTestFeedbackChange={handleTestAgentFeedbackChange}
|
onTestFeedbackChange={handleTestAgentFeedbackChange}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue