MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / extractOutputText

Function extractOutputText

sdk/src/__tests__/run.integration.test.ts:13–34  ·  view source on GitHub ↗
(output: AgentOutput)

Source from the content-addressed store, hash-verified

11const apiKey = process.env.CODEBUFF_API_KEY
12
13function extractOutputText(output: AgentOutput): string {
14 if (output.type !== 'lastMessage' && output.type !== 'allMessages') return ''
15 const messages = output.value as { role: string; content: unknown }[]
16 for (const msg of messages) {
17 if (msg.role !== 'assistant') continue
18 if (typeof msg.content === 'string') return msg.content
19 if (Array.isArray(msg.content)) {
20 for (const part of msg.content) {
21 if (
22 typeof part === 'object' &&
23 part !== null &&
24 'type' in part &&
25 part.type === 'text' &&
26 'text' in part
27 ) {
28 return String(part.text)
29 }
30 }
31 }
32 }
33 return ''
34}
35
36describe('Prompt Caching', () => {
37 it(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected