* feat(client): publish the TypeScript SDK surface Make the high-level client API usable for external integrations and document complete agent, workspace, provider, event, and recipe flows. * fix(client): correlate provider snapshots by daemon cwd Return the daemon's canonical snapshot identity so waitForReady can match updates for relative, tilde, and otherwise non-canonical paths without duplicating filesystem rules in the SDK. * test(server): make snapshot cwd assertion portable * fix(client): gate canonical provider snapshot waits Older daemons do not expose the canonical snapshot identity needed to correlate workspace updates safely. Require the advertised capability and fail with an update-host message instead of guessing across workspaces.
68 lines
1.8 KiB
TypeScript
68 lines
1.8 KiB
TypeScript
import { createPaseoClient, type PaseoClient } from "@getpaseo/client";
|
|
|
|
export function createClient(url: string): PaseoClient {
|
|
return createPaseoClient({
|
|
url,
|
|
});
|
|
}
|
|
|
|
export async function createCodexAgent(url: string, cwd: string): Promise<string> {
|
|
const client = createClient(url);
|
|
|
|
try {
|
|
await client.connect();
|
|
|
|
const agent = await client.agents.create({
|
|
config: {
|
|
provider: "codex/gpt-5.5",
|
|
modeId: "full-access",
|
|
},
|
|
cwd,
|
|
prompt: "Inspect this repository and summarize the next useful task.",
|
|
});
|
|
|
|
return agent.id;
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
}
|
|
|
|
export async function chooseProviderFromSnapshot(url: string, cwd: string): Promise<string> {
|
|
const client = createClient(url);
|
|
|
|
try {
|
|
await client.connect();
|
|
|
|
const snapshot = await client.providers.waitForReady({ cwd });
|
|
const readyProvider = snapshot.entries.find((provider) => provider.status === "ready");
|
|
const model =
|
|
readyProvider?.models?.find((candidate) => candidate.isDefault) ?? readyProvider?.models?.[0];
|
|
if (!readyProvider || !model) throw new Error("No provider model is ready");
|
|
|
|
const agent = await client.agents.create({
|
|
config: {
|
|
provider: `${readyProvider.provider}/${model.id}`,
|
|
},
|
|
cwd,
|
|
prompt: "Start with a quick repository map.",
|
|
});
|
|
|
|
return agent.id;
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
}
|
|
|
|
export async function runFollowUp(url: string, agentId: string): Promise<string | null> {
|
|
const client = createClient(url);
|
|
|
|
try {
|
|
await client.connect();
|
|
const result = await client.agents.ref(agentId).run("Summarize your progress and next step.");
|
|
if (result.status !== "idle") throw new Error(result.error ?? result.status);
|
|
return result.lastMessage;
|
|
} finally {
|
|
await client.close();
|
|
}
|
|
}
|