Skip to content
Merged
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
14 changes: 14 additions & 0 deletions packages/app/src/exe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ export interface ExeConnection {
agentCommand?: string;
/** Per-job harness model. Empty means the harness chooses its default. */
model?: string;
/** Models returned by the VM's attached exe.dev LLM integration. */
models?: string[];
modelsRefreshedAt?: string;
}

export interface ExeResponse {
Expand Down Expand Up @@ -160,6 +163,17 @@ export function connectionCheckCommand(): string {
return "printf '%s\\n' factorize-connection-ok";
}

/** Query the documented exe.dev LLM integration from inside the connected VM. */
export function modelListCommand(): string {
return "curl --fail --silent --show-error https://llm.int.exe.xyz/v1/models | jq -cer '[.data[]?.id | strings] | unique'";
}

export function parseModelList(value: string): string[] {
const parsed: unknown = JSON.parse(value);
if (!Array.isArray(parsed) || parsed.some(model => typeof model !== "string")) throw new Error("The model endpoint returned an invalid response");
return [...new Set(parsed.map(model => model.trim()).filter(Boolean))].sort();
}

/** exe.dev executes non-interactive shells, which do not load the user's PATH customizations. */
function herdrPrefix(connection: ExeConnection): string {
return `export PATH="$HOME/.local/bin:$PATH" && command -v ${shellAtom(herdrBinary(connection))} >/dev/null`;
Expand Down
4 changes: 4 additions & 0 deletions packages/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ app.post("/api/connections/exe/test", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch("https://tenant/connections/exe/test", { method: "POST", headers: { "Content-Type": "application/json" }, body: await c.req.text() });
});
app.post("/api/connections/exe/:id/models", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch(`https://tenant/connections/exe/${encodeURIComponent(c.req.param("id"))}/models`, { method: "POST" });
});
app.put("/api/connections/amp", async (c) => {
const session = await owner(c); if (!session) return c.json({ error: "Unauthorized" }, 401);
return tenant(c, session.tenantId).fetch("https://tenant/connections/amp", { method: "PUT", headers: { "Content-Type": "application/json" }, body: await c.req.text() });
Expand Down
32 changes: 28 additions & 4 deletions packages/app/src/tenant.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DurableObject } from "cloudflare:workers";
import Mustache from "mustache";
import { decrypt, encrypt, equalHmac } from "./crypto";
import { agentListCommand, agentOutputCommand, agentStartupBlocked, agentStatusCommand, connectionCheckCommand, defaultAgentCommand, exec, garbageCollectPaneCommand, herdrAgentStatus, herdrCheckCommand, paneGetCommand, paneProcessInfoCommand, replaceForegroundCommand, startAgentCommand, startAgentInPaneCommand, stopAgentCommand, validateWorktreeLeaseCommand, type ExeConnection } from "./exe";
import { agentListCommand, agentOutputCommand, agentStartupBlocked, agentStatusCommand, connectionCheckCommand, defaultAgentCommand, exec, garbageCollectPaneCommand, herdrAgentStatus, herdrCheckCommand, modelListCommand, paneGetCommand, paneProcessInfoCommand, parseModelList, replaceForegroundCommand, startAgentCommand, startAgentInPaneCommand, stopAgentCommand, validateWorktreeLeaseCommand, type ExeConnection } from "./exe";
import { findOwnedAgent, ownsPane, parseAgent, parseAgentList, parsePaneProcess, type HerdrIdentity } from "./recovery";
import { LINEAR_ISSUE_PROJECT_QUERY, LINEAR_OPTION_QUERIES, LINEAR_PROJECTS_QUERY, isLinearAuthenticationError, refreshLinearToken } from "./linear";
import { matchingIssue } from "./matcher";
Expand Down Expand Up @@ -223,6 +223,8 @@ export class TenantV2 extends DurableObject<Env> {
if (request.method === "PUT" && url.pathname === "/connections/clickup") return await this.saveClickUp(await request.json());
if (request.method === "PUT" && url.pathname === "/connections/exe") return await this.saveExe(await request.json());
if (request.method === "POST" && url.pathname === "/connections/exe/test") return await this.testExe(await request.json());
const exeModelsMatch = url.pathname.match(/^\/connections\/exe\/([^/]+)\/models$/);
if (request.method === "POST" && exeModelsMatch) return await this.refreshExeModels(decodeURIComponent(exeModelsMatch[1]));
if (request.method === "PUT" && url.pathname === "/connections/amp") return await this.saveAmp(await request.json());
if (request.method === "POST" && url.pathname === "/connections/amp/test") return await this.testAmp(await request.json());
if (request.method === "GET" && url.pathname === "/connections/cloudflare-tail") return json(await this.tailIntegrationStatus());
Expand Down Expand Up @@ -310,12 +312,32 @@ export class TenantV2 extends DurableObject<Env> {
throw new Error(`This token cannot run ssh commands on ${value.vmName}. Create an exe.dev API token with --cmds="'ssh ${value.vmName}'" (not --vm), then paste the new exe1 token.`);
}
if (!verification.ok) throw new Error(`exe.dev/Herdr verification failed (${verification.status}): ${verification.body.slice(0, 300)}`);
const models = await this.discoverExeModels(value);
const connectionId = value.connectionId || id();
await this.putConnection(`exe:${connectionId}`, value);
const saved = { ...value, models, modelsRefreshedAt: now() };
await this.putConnection(`exe:${connectionId}`, saved);
// Preserve the most recently saved connection for existing flows created
// before connections were selectable.
await this.putConnection("exe", value);
return json({ ok: true, connectionId, verification: verification.body });
await this.putConnection("exe", saved);
return json({ ok: true, connectionId, verification: verification.body, models });
}

private async discoverExeModels(connection: ExeConnection): Promise<string[]> {
const result = await exec(connection, modelListCommand());
if (!result.ok) throw new Error(`Could not load models from the exe.dev LLM integration (${result.status}): ${result.body.slice(0, 300)}`);
try { return parseModelList(result.body); }
catch (error) { throw new Error(error instanceof Error ? error.message : "The model endpoint returned an invalid response"); }
}

private async refreshExeModels(connectionId: string): Promise<Response> {
const connection = await this.connection<ExeConnection>(`exe:${connectionId}`);
if (!connection) throw new Error("Exe.dev connection not found");
const models = await this.discoverExeModels(connection);
const saved = { ...connection, models, modelsRefreshedAt: now() };
await this.putConnection(`exe:${connectionId}`, saved);
const legacy = await this.connection<ExeConnection>("exe");
if (legacy?.vmName === connection.vmName && legacy.cwd === connection.cwd && legacy.agentKind === connection.agentKind) await this.putConnection("exe", saved);
return json({ ok: true, models, modelsRefreshedAt: saved.modelsRefreshedAt });
}

private async testExe(input: unknown): Promise<Response> {
Expand Down Expand Up @@ -451,6 +473,8 @@ export class TenantV2 extends DurableObject<Env> {
workspace: connection.vmName,
cwd: connection.cwd,
agentKind: connection.agentKind,
models: connection.models ?? [],
modelsRefreshedAt: connection.modelsRefreshedAt ?? null,
capabilities: ["output", "prompt-delivery", "recovery", "stop"],
})), ...ampConnections.map(connection => ({ id: `amp:${connection.connectionId}`, kind: "amp", name: `Amp · ${connection.project}`, workspace: connection.project, cwd: "Cloud orb", agentKind: "Amp", capabilities: ["stop"] }))]);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export interface ExeConnectionInput {
herdrCommand?: string;
/** Arguments passed to Herdr's canonical executable for the selected kind. */
agentCommand?: string;
models?: string[];
modelsRefreshedAt?: string;
}

export interface AmpConnectionInput { connectionId?: string; accessToken: string; project: string; apiBaseUrl?: string; }
Expand Down
Loading