Files
oh-my-opencode/src/tools/council-archive/council-response-extractor.ts
T

32 lines
1.1 KiB
TypeScript
Raw Normal View History

export const MIN_RESPONSE_LENGTH = 100
export const OPENING_TAG = "<COUNCIL_MEMBER_RESPONSE>"
export const CLOSING_TAG = "</COUNCIL_MEMBER_RESPONSE>"
export interface CouncilResponseExtraction {
has_response: boolean
response_complete: boolean
result: string | null
}
export function extractCouncilResponse(fullText: string): CouncilResponseExtraction {
const lastOpenIdx = fullText.lastIndexOf(OPENING_TAG)
if (lastOpenIdx === -1) {
return { has_response: false, response_complete: false, result: null }
}
const contentStart = lastOpenIdx + OPENING_TAG.length
const closingAfterLastOpen = fullText.indexOf(CLOSING_TAG, contentStart)
if (closingAfterLastOpen === -1) {
const partial = fullText.slice(contentStart).trim()
return { has_response: true, response_complete: false, result: partial || null }
}
const content = fullText.slice(contentStart, closingAfterLastOpen).trim()
if (content.length < MIN_RESPONSE_LENGTH) {
return { has_response: false, response_complete: true, result: content }
}
return { has_response: true, response_complete: true, result: content }
}