mirror of
https://github.com/block/buzz.git
synced 2026-11-08 18:31:56 +00:00
feat(desktop): rebuild agent activity feed around a classifier registry and twelve render classes (#1381)
Signed-off-by: Taylor Ho <taylorkmho@gmail.com> Co-authored-by: npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w <52a228d6edf316ec6812ac3c9fc0d696ab59fc7954d77e7be31eedcddf91335b@sprout-oss.stage.blox.sqprod.co> Co-authored-by: npub14vtk7pvazqrq9639qu7e560wnqtl0d53ca4gjuvq6jzf3k2el23qqlwa7f <ab176f059d100602ea25073d9a69ee9817f7b691c76a897180d48498d959faa2@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
@@ -18,6 +18,7 @@ export function parsePromptText(text: string): {
|
||||
userText: string;
|
||||
userTitle: string;
|
||||
userPubkey: string | null;
|
||||
userEventId: string | null;
|
||||
} {
|
||||
const sections = parsePromptSections(text).filter(
|
||||
(s) => s.body.trim().length > 0,
|
||||
@@ -28,12 +29,13 @@ export function parsePromptText(text: string): {
|
||||
userText: text.trim(),
|
||||
userTitle: "Prompt",
|
||||
userPubkey: null,
|
||||
userEventId: null,
|
||||
};
|
||||
}
|
||||
|
||||
const eventSection = sections.find((section) => {
|
||||
const title = section.title.toLowerCase();
|
||||
return title.startsWith("buzz event") || title.startsWith("buzz event");
|
||||
return title.startsWith("buzz event");
|
||||
});
|
||||
const eventContent = eventSection
|
||||
? extractEventContent(eventSection.body)
|
||||
@@ -41,6 +43,7 @@ export function parsePromptText(text: string): {
|
||||
const eventAuthorPubkey = eventSection
|
||||
? extractEventAuthorPubkey(eventSection.body)
|
||||
: null;
|
||||
const eventId = eventSection ? extractEventId(eventSection.body) : null;
|
||||
const eventKind = eventSection?.title.split(":").slice(1).join(":").trim();
|
||||
|
||||
return {
|
||||
@@ -48,6 +51,7 @@ export function parsePromptText(text: string): {
|
||||
userText: eventContent,
|
||||
userTitle: eventKind ? titleCase(eventKind) : "Buzz event",
|
||||
userPubkey: eventAuthorPubkey,
|
||||
userEventId: eventId,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -127,9 +131,39 @@ function parsePromptSections(text: string): PromptSection[] {
|
||||
return sections;
|
||||
}
|
||||
|
||||
const EVENT_CONTENT_BOUNDARY_RE =
|
||||
/^(?:Event ID|Channel|Kind|From|Time|Tags|Parsed):\s*/;
|
||||
const EVENT_BLOCK_BOUNDARY_RE = /^--- Event \d+\b/;
|
||||
|
||||
function extractEventContent(body: string): string {
|
||||
const contentMatch = body.match(/^Content:\s*(.*)$/m);
|
||||
return contentMatch?.[1]?.trim() ?? "";
|
||||
const lines = body.split(/\r?\n/);
|
||||
const chunks: string[] = [];
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const match = lines[i].match(/^Content:\s?(.*)$/);
|
||||
if (!match) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const contentLines = [match[1] ?? ""];
|
||||
for (let j = i + 1; j < lines.length; j++) {
|
||||
const line = lines[j];
|
||||
if (
|
||||
EVENT_CONTENT_BOUNDARY_RE.test(line) ||
|
||||
EVENT_BLOCK_BOUNDARY_RE.test(line)
|
||||
) {
|
||||
break;
|
||||
}
|
||||
contentLines.push(line);
|
||||
}
|
||||
|
||||
const content = contentLines.join("\n").trim();
|
||||
if (content) {
|
||||
chunks.push(content);
|
||||
}
|
||||
}
|
||||
|
||||
return chunks.join("\n\n");
|
||||
}
|
||||
|
||||
function extractEventAuthorPubkey(body: string): string | null {
|
||||
@@ -137,6 +171,11 @@ function extractEventAuthorPubkey(body: string): string | null {
|
||||
return fromMatch?.[1]?.toLowerCase() ?? null;
|
||||
}
|
||||
|
||||
function extractEventId(body: string): string | null {
|
||||
const eventIdMatch = body.match(/^Event ID:\s*([0-9a-fA-F]{64})\b/m);
|
||||
return eventIdMatch?.[1]?.toLowerCase() ?? null;
|
||||
}
|
||||
|
||||
export function extractContentText(value: unknown): string {
|
||||
if (typeof value === "string") return value;
|
||||
if (Array.isArray(value)) return value.map(extractBlockText).join("\n");
|
||||
@@ -242,13 +281,17 @@ export function extractToolResult(update: Record<string, unknown>): string {
|
||||
return extractBlockText(update.rawOutput);
|
||||
}
|
||||
|
||||
export function describeTurnStarted(payload: unknown): string {
|
||||
export function extractTriggeringEventIds(payload: unknown): string[] {
|
||||
const record = asRecord(payload);
|
||||
const ids = Array.isArray(record.triggeringEventIds)
|
||||
return Array.isArray(record.triggeringEventIds)
|
||||
? record.triggeringEventIds.filter(
|
||||
(id): id is string => typeof id === "string",
|
||||
)
|
||||
: [];
|
||||
}
|
||||
|
||||
export function describeTurnStarted(payload: unknown): string {
|
||||
const ids = extractTriggeringEventIds(payload);
|
||||
return ids.length > 0
|
||||
? `Triggered by ${ids.length === 1 ? "1 event" : `${ids.length} events`}.`
|
||||
: "";
|
||||
|
||||
Reference in New Issue
Block a user