Files
paseo/packages/client/examples/agents-and-providers.ts
paseo-bot[bot]andDaye f232d23e9a fix(client): let SDK callers choose what a send does to an active turn (#5605)
PaseoAgentSendOptions was a hand-copied subset of the daemon client's
SendMessageOptions and dropped activeTurnBehavior, so
agents.ref(id).send(text, { activeTurnBehavior: "steer" }) and run() failed
to typecheck even though the value is forwarded to the daemon. The public
type is now the options type send() passes through, so the two cannot
drift again.

Closes #4555

Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Daye <2077152374@qq.com>
2026-09-29 06:53:14 +02:00

81 lines
2.2 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.", {
activeTurnBehavior: "interrupt",
});
if (result.status !== "idle") throw new Error(result.error ?? result.status);
return result.lastMessage;
} finally {
await client.close();
}
}
export async function steerAgent(url: string, agentId: string, prompt: string): Promise<void> {
const client = createClient(url);
try {
await client.connect();
await client.agents.ref(agentId).send(prompt, { activeTurnBehavior: "steer" });
} finally {
await client.close();
}
}