MCPcopy Create free account
hub / github.com/backnotprop/plannotator / getRecentAssistantMessages

Function getRecentAssistantMessages

apps/opencode-plugin/cli-bridge.ts:382–410  ·  view source on GitHub ↗
(
  client: OpenCodeClient,
  sessionId: string,
  limit = 25,
)

Source from the content-addressed store, hash-verified

380}
381
382export async function getRecentAssistantMessages(
383 client: OpenCodeClient,
384 sessionId: string,
385 limit = 25,
386): Promise<RecentAssistantMessage[]> {
387 const messagesResponse = await client.session?.messages?.({
388 path: { id: sessionId },
389 });
390 const messages = messagesResponse?.data;
391 if (!messages) return [];
392
393 const recentMessages: RecentAssistantMessage[] = [];
394 for (let i = messages.length - 1; i >= 0; i--) {
395 if (recentMessages.length >= limit) break;
396 const msg = messages[i];
397 if (msg.info?.role !== "assistant") continue;
398 const textParts = (msg.parts ?? [])
399 .filter((part: any) => part.type === "text" && part.text?.trim())
400 .map((part: any) => part.text);
401 if (textParts.length === 0) continue;
402 recentMessages.push({
403 messageId: msg.info?.id ?? `opencode-${i}`,
404 text: textParts.join("\n"),
405 timestamp: msg.info?.time?.created ? new Date(msg.info.time.created).toISOString() : undefined,
406 });
407 }
408
409 return recentMessages;
410}
411
412export function buildReviewPromptFromBridgeOutcome(outcome: CliReviewOutcome): {
413 message: string | null;

Callers 2

cli-bridge.test.tsFile · 0.90
handleCliCommandFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected