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
7 changes: 7 additions & 0 deletions packages/client-runtime/src/state/subagentRuntime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ describe("projectedSubagentsToRuntime workflow expansion", () => {
expect(members?.[0]?.speed).toBeUndefined();
},
);

it("titles an untitled subagent from its prompt without splitting an emoji", () => {
const [untitled] = projectedSubagentsToRuntime([
subagent({ title: null, prompt: `${"a".repeat(76)}😀 and more work.` }),
]);
expect(untitled?.title).toBe(`${"a".repeat(76)}...`);
});
});

describe("deriveWorkflowGroups over a dynamic workflow", () => {
Expand Down
15 changes: 12 additions & 3 deletions packages/client-runtime/src/state/subagentRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,17 @@ function workflowMembersToRuntime(
});
}

function promptTitle(prompt: string): string {
if (prompt.length <= 80) return prompt;
let end = 77;
const previous = prompt.charCodeAt(end - 1);
const next = prompt.charCodeAt(end);
if (previous >= 0xd800 && previous <= 0xdbff && next >= 0xdc00 && next <= 0xdfff) {
end -= 1;
}
return `${prompt.slice(0, end)}...`;
}

export function workflowMemberModelSelection(
member: Pick<RuntimeSubagent, "model" | "effort" | "speed">,
instanceId: ModelSelection["instanceId"],
Expand Down Expand Up @@ -216,9 +227,7 @@ export function projectedSubagentsToRuntime(
const coordinator = {
id: subagent.id,
kind: workflow === undefined ? "subagent" : "workflow",
title:
subagent.title ??
(subagent.prompt.length > 80 ? `${subagent.prompt.slice(0, 77)}...` : subagent.prompt),
title: subagent.title ?? promptTitle(subagent.prompt),
role: null,
model: subagent.model,
effort: null,
Expand Down
Loading