mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-20 07:15:25 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78eb6aa770 | ||
|
|
6ff1c4deca | ||
|
|
91fac29fae |
@@ -66,4 +66,23 @@ describe("fetchAgentCommands", () => {
|
||||
|
||||
expect(client.calls).toEqual([{ agentId: "agent-1", draftConfig: undefined }]);
|
||||
});
|
||||
|
||||
it("deduplicates duplicate command names from the daemon, keeping the first entry", async () => {
|
||||
const client = createClient(
|
||||
commandsPayload([
|
||||
{ name: "goal", description: "Run until goal is finished", argumentHint: "" },
|
||||
{ name: "plan", description: "Plan carefully before executing a task.", argumentHint: "" },
|
||||
{ name: "plan", description: "Local plan skill description", argumentHint: "" },
|
||||
{ name: "review", description: "Review changes", argumentHint: "" },
|
||||
]),
|
||||
);
|
||||
|
||||
const commands = await fetchAgentCommands({ client, agentId: "agent-1" });
|
||||
|
||||
expect(commands).toEqual([
|
||||
{ name: "goal", description: "Run until goal is finished", argumentHint: "" },
|
||||
{ name: "plan", description: "Plan carefully before executing a task.", argumentHint: "" },
|
||||
{ name: "review", description: "Review changes", argumentHint: "" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -37,6 +37,18 @@ export interface AgentCommandsClient {
|
||||
listCommands(options: ListAgentCommandsOptions): ReturnType<DaemonClient["listCommands"]>;
|
||||
}
|
||||
|
||||
// COMPAT(dedupeListCommands): added in v0.17.0, remove after 2027-05-20 once daemon floor >= v0.17.0.
|
||||
function dedupeSlashCommands(commands: readonly AgentSlashCommand[]): AgentSlashCommand[] {
|
||||
const seen = new Set<string>();
|
||||
const unique: AgentSlashCommand[] = [];
|
||||
for (const command of commands) {
|
||||
if (seen.has(command.name)) continue;
|
||||
seen.add(command.name);
|
||||
unique.push(command);
|
||||
}
|
||||
return unique;
|
||||
}
|
||||
|
||||
export async function fetchAgentCommands(input: {
|
||||
client: AgentCommandsClient;
|
||||
agentId: string;
|
||||
@@ -47,7 +59,7 @@ export async function fetchAgentCommands(input: {
|
||||
draftConfig: input.draftConfig,
|
||||
});
|
||||
if (response.error) throw new Error(response.error);
|
||||
return response.commands as AgentSlashCommand[];
|
||||
return dedupeSlashCommands(response.commands as AgentSlashCommand[]);
|
||||
}
|
||||
|
||||
interface UseAgentCommandsQueryOptions {
|
||||
|
||||
@@ -6661,3 +6661,77 @@ test("does not publish internal agents' background work to subscribed clients",
|
||||
await new Promise<void>((resolve) => setImmediate(resolve));
|
||||
expect(messages.some((message) => message.type === "agent.background_work.update")).toBe(false);
|
||||
});
|
||||
|
||||
test("deduplicates repeated command names in list_commands_response for live agents and drafts", async () => {
|
||||
const duplicateCommands = [
|
||||
{
|
||||
name: "goal",
|
||||
description: "Run until goal is finished",
|
||||
argumentHint: "",
|
||||
kind: "command" as const,
|
||||
},
|
||||
{
|
||||
name: "plan",
|
||||
description: "Plan carefully before executing a task.",
|
||||
argumentHint: "",
|
||||
kind: "command" as const,
|
||||
},
|
||||
{
|
||||
name: "plan",
|
||||
description: "Local plan skill description",
|
||||
argumentHint: "",
|
||||
kind: "skill" as const,
|
||||
},
|
||||
];
|
||||
const expected = [duplicateCommands[0], duplicateCommands[1]];
|
||||
|
||||
const liveMessages: SessionOutboundMessage[] = [];
|
||||
const liveSession = createSessionForTest({
|
||||
messages: liveMessages,
|
||||
agentManager: {
|
||||
waitForAgentClose: async () => undefined,
|
||||
getAgent: () =>
|
||||
({
|
||||
id: "agent-1",
|
||||
session: { listCommands: async () => duplicateCommands },
|
||||
}) as never,
|
||||
},
|
||||
});
|
||||
await liveSession.handleMessage({
|
||||
type: "list_commands_request",
|
||||
agentId: "agent-1",
|
||||
requestId: "req-live",
|
||||
});
|
||||
expect(findByType(liveMessages, "list_commands_response")).toMatchObject({
|
||||
payload: {
|
||||
agentId: "agent-1",
|
||||
requestId: "req-live",
|
||||
error: null,
|
||||
commands: expected,
|
||||
},
|
||||
});
|
||||
|
||||
const draftMessages: SessionOutboundMessage[] = [];
|
||||
const draftSession = createSessionForTest({
|
||||
messages: draftMessages,
|
||||
agentManager: {
|
||||
getAgent: () => undefined,
|
||||
listDraftCommands: async () => duplicateCommands,
|
||||
},
|
||||
agentStorage: { get: async () => null },
|
||||
});
|
||||
await draftSession.handleMessage({
|
||||
type: "list_commands_request",
|
||||
agentId: "draft-1",
|
||||
requestId: "req-draft",
|
||||
draftConfig: { provider: "antigravity", cwd: "/tmp/repo" },
|
||||
});
|
||||
expect(findByType(draftMessages, "list_commands_response")).toMatchObject({
|
||||
payload: {
|
||||
agentId: "draft-1",
|
||||
requestId: "req-draft",
|
||||
error: null,
|
||||
commands: expected,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5603,7 +5603,7 @@ export class Session {
|
||||
: null;
|
||||
|
||||
if (agent?.session?.listCommands) {
|
||||
const commands = await agent.session.listCommands();
|
||||
const commands = dedupeSlashCommands(await agent.session.listCommands());
|
||||
this.emit({
|
||||
type: "list_commands_response",
|
||||
payload: {
|
||||
@@ -5627,7 +5627,9 @@ export class Session {
|
||||
: {}),
|
||||
};
|
||||
|
||||
const commands = await this.agentManager.listDraftCommands(sessionConfig);
|
||||
const commands = dedupeSlashCommands(
|
||||
await this.agentManager.listDraftCommands(sessionConfig),
|
||||
);
|
||||
this.emit({
|
||||
type: "list_commands_response",
|
||||
payload: {
|
||||
@@ -9614,3 +9616,14 @@ function createHostSession(options: SessionOptions, session: Session): Connected
|
||||
function hostSource(options: SessionOptions): string {
|
||||
return options.sourceId ?? "owner";
|
||||
}
|
||||
|
||||
function dedupeSlashCommands<T extends { name: string }>(commands: readonly T[]): T[] {
|
||||
const seen = new Set<string>();
|
||||
const unique: T[] = [];
|
||||
for (const command of commands) {
|
||||
if (seen.has(command.name)) continue;
|
||||
seen.add(command.name);
|
||||
unique.push(command);
|
||||
}
|
||||
return unique;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user