import type { ACPMessage, GoatChainAgent } from '../acp'

export function createErrorDimSdkAgent(error: unknown): GoatChainAgent {
  const message
    = error instanceof Error ? error.stack || error.message : String(error)
  const body = ['# DimCode error', '', '```text', message, '```'].join('\n')

  return {
    async *receiveMessage() {
      yield {
        role: 'assistant',
        content: body,
        metadata: {
          done: true,
          error: true,
          stopReason: 'error',
          originalEventType: 'done',
        },
      } satisfies ACPMessage
    },
  }
}

export { createErrorDimSdkAgent as createErrorGoatChainAgent }
