mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-02 13:15:21 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
423178804f | ||
|
|
5f3396fec0 |
@@ -81,6 +81,11 @@ describe("buildAgentLsFetchOptions", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves empty values and punctuation in repeated label filters", () => {
|
||||
const options = buildAgentLsFetchOptions({ label: ["tag=v=1,rc", "empty="] });
|
||||
expect(options.filter?.labels).toEqual({ tag: "v=1,rc", empty: "" });
|
||||
});
|
||||
|
||||
it("asks the daemon for internal agents only with --internal", () => {
|
||||
expect(buildAgentLsFetchOptions({ background: true, global: true })).toEqual({
|
||||
filter: { includeBackground: true },
|
||||
@@ -126,6 +131,17 @@ describe("buildAgentLsFetchOptions", () => {
|
||||
});
|
||||
|
||||
describe("runLsCommand", () => {
|
||||
it.each(["team", "=blue", " =blue"])(
|
||||
"rejects the whole listing when a label filter is malformed (%j)",
|
||||
async (label) => {
|
||||
await expect(
|
||||
listAgents({ daemonTarget, label: ["bot=worker", label] }, async () =>
|
||||
createPagingClient(),
|
||||
),
|
||||
).rejects.toMatchObject({ code: "INVALID_LABEL", message: `Invalid label format: ${label}` });
|
||||
},
|
||||
);
|
||||
|
||||
it("includes agent snapshot metadata in JSON listings", async () => {
|
||||
const result = await listAgents({ daemonTarget, global: true }, async () =>
|
||||
createPagingClient(),
|
||||
|
||||
@@ -141,16 +141,20 @@ export interface AgentLsOptions extends CommandOptions {
|
||||
}
|
||||
|
||||
function parseLabelFilters(labels: string[] | undefined): Record<string, string> {
|
||||
const labelFilters: Record<string, string> = {};
|
||||
for (const labelStr of labels ?? []) {
|
||||
const eqIndex = labelStr.indexOf("=");
|
||||
if (eqIndex !== -1) {
|
||||
const key = labelStr.slice(0, eqIndex);
|
||||
const value = labelStr.slice(eqIndex + 1);
|
||||
labelFilters[key] = value;
|
||||
}
|
||||
}
|
||||
return labelFilters;
|
||||
return Object.fromEntries(
|
||||
(labels ?? []).map((label) => {
|
||||
const separator = label.indexOf("=");
|
||||
const key = label.slice(0, separator);
|
||||
if (separator === -1 || !key.trim()) {
|
||||
throw {
|
||||
code: "INVALID_LABEL",
|
||||
message: `Invalid label format: ${label}`,
|
||||
details: "Labels must include a non-empty key in key=value format",
|
||||
} satisfies CommandError;
|
||||
}
|
||||
return [key, label.slice(separator + 1)];
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function buildAgentLsFetchOptions(
|
||||
@@ -211,6 +215,7 @@ export async function listAgents(
|
||||
options: Parameters<typeof connectToDaemon>[0],
|
||||
) => Promise<AgentLsClient> = connectToDaemon,
|
||||
): Promise<AgentLsResult> {
|
||||
const fetchOptions = buildAgentLsFetchOptions(options);
|
||||
const client = await connect({ target: options.daemonTarget });
|
||||
|
||||
try {
|
||||
@@ -223,8 +228,6 @@ export async function listAgents(
|
||||
throw error;
|
||||
}
|
||||
|
||||
const labelFilters = parseLabelFilters(options.label);
|
||||
const fetchOptions = buildAgentLsFetchOptions(options);
|
||||
let agents = await fetchAllAgents(client, fetchOptions);
|
||||
|
||||
// By default, exclude archived agents. `-a` includes them.
|
||||
@@ -243,7 +246,8 @@ export async function listAgents(
|
||||
}
|
||||
|
||||
// Apply label filtering only when explicitly requested.
|
||||
if (Object.keys(labelFilters).length > 0) {
|
||||
const labelFilters = fetchOptions.filter?.labels;
|
||||
if (labelFilters) {
|
||||
agents = agents.filter((a) => {
|
||||
const agentLabels = a.labels;
|
||||
for (const [key, value] of Object.entries(labelFilters)) {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { lastAssistantMessageText } from "../../../assistant-message.js";
|
||||
import { projectTimelineRows } from "../../../timeline-projection.js";
|
||||
import { collectTimelineSnapshot } from "../test-utils/v2-timeline.js";
|
||||
import type { SessionMessageAssistant } from "@opencode/client";
|
||||
import { execFileSync } from "node:child_process";
|
||||
@@ -136,3 +138,37 @@ test.each(["delta", "snapshot"] as const)(
|
||||
expect(retainedBytesAfterStreaming(mode, chunks)).toBeLessThan(textBytes * 32);
|
||||
},
|
||||
);
|
||||
|
||||
test.each(["snapshot", "stream"] as const)(
|
||||
"empty reasoning between two text parts keeps their paragraphs distinct in %s",
|
||||
async (mode) => {
|
||||
const timeline = new V2Timeline();
|
||||
const message = assistant([
|
||||
{ type: "text", text: "I checked content search." },
|
||||
{ type: "reasoning", text: "" },
|
||||
{ type: "text", text: "The newly named tool works." },
|
||||
]);
|
||||
const liveEvents = [];
|
||||
if (mode === "stream") {
|
||||
const commentary = { assistantMessageID: message.id, type: "text" as const, ordinal: 0 };
|
||||
timeline.startPart(commentary);
|
||||
liveEvents.push(timeline.delta({ ...commentary, delta: "I checked content search." }));
|
||||
const final = { ...commentary, ordinal: 1 };
|
||||
timeline.startPart(final);
|
||||
liveEvents.push(timeline.delta({ ...final, delta: "The newly" }));
|
||||
}
|
||||
const replayEvents = await collectTimelineSnapshot(timeline, [message]);
|
||||
const rows = [...liveEvents, ...replayEvents].flatMap((event, index) =>
|
||||
event?.type === "timeline"
|
||||
? [{ item: event.item, timestamp: event.timestamp, seq: index + 1, turnId: "turn" }]
|
||||
: [],
|
||||
);
|
||||
const replies = projectTimelineRows({ rows, mode: "projected" }).flatMap(({ item }) =>
|
||||
item.type === "assistant_message" ? [item.text] : [],
|
||||
);
|
||||
|
||||
const expected = "I checked content search.\n\nThe newly named tool works.";
|
||||
expect.soft(replies).toEqual([expected]);
|
||||
expect.soft(lastAssistantMessageText(rows)).toBe(expected);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -49,11 +49,13 @@ export class V2Timeline {
|
||||
if (!text.startsWith(emitted))
|
||||
throw new Error("OpenCode changed previously emitted message content");
|
||||
this.content.set(key, text);
|
||||
const suffix = detachedSuffix(text, emitted.length);
|
||||
const item: AgentTimelineItem =
|
||||
event.type === "text"
|
||||
? { type: "assistant_message", text: suffix, messageId: event.assistantMessageID }
|
||||
: { type: "reasoning", text: suffix };
|
||||
const item = this.textItem({
|
||||
messageID: event.assistantMessageID,
|
||||
type: event.type,
|
||||
ordinal: event.ordinal,
|
||||
text,
|
||||
previous: emitted,
|
||||
});
|
||||
return { type: "timeline", provider: "opencode", item, timestamp: new Date().toISOString() };
|
||||
}
|
||||
|
||||
@@ -199,10 +201,35 @@ export class V2Timeline {
|
||||
if (!part.text.startsWith(previous))
|
||||
throw new Error("OpenCode changed previously emitted message content");
|
||||
this.content.set(key, part.text);
|
||||
const suffix = detachedSuffix(part.text, previous.length);
|
||||
if (part.type === "text")
|
||||
push({ type: "assistant_message", text: suffix, messageId: messageID });
|
||||
else push({ type: "reasoning", text: suffix });
|
||||
push(this.textItem({ messageID, type: part.type, ordinal, text: part.text, previous }));
|
||||
}
|
||||
|
||||
private textItem({
|
||||
messageID,
|
||||
type,
|
||||
ordinal,
|
||||
text,
|
||||
previous,
|
||||
}: {
|
||||
messageID: string;
|
||||
type: "text" | "reasoning";
|
||||
ordinal: number;
|
||||
text: string;
|
||||
previous: string;
|
||||
}): AgentTimelineItem {
|
||||
const suffix = detachedSuffix(text, previous.length);
|
||||
if (type === "reasoning") return { type: "reasoning", text: suffix };
|
||||
|
||||
// Projection joins chunks with the same message ID. Separate OpenCode text parts
|
||||
// once, at the first emitted chunk, so live output and history replay agree.
|
||||
if (previous.length === 0) {
|
||||
for (let earlier = ordinal - 1; earlier >= 0; earlier--) {
|
||||
if (this.content.has(textPartKey(messageID, "text", earlier))) {
|
||||
return { type: "assistant_message", text: `\n\n${suffix}`, messageId: messageID };
|
||||
}
|
||||
}
|
||||
}
|
||||
return { type: "assistant_message", text: suffix, messageId: messageID };
|
||||
}
|
||||
|
||||
private async toolPart(
|
||||
|
||||
Reference in New Issue
Block a user