conversation.spec.ts 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. /** Assistant block classifier (moved here with sessions/conversation.ts). */
  2. import { describe, expect, it } from 'vitest'
  3. import { AttachmentId } from '@deepseek-ai/dsh-attachment'
  4. import type { ContentBlock } from '@deepseek-ai/dsh-client-connection/client'
  5. import { toAssistantBlock, toAssistantBlocks } from '../src/client/sessions/conversation.ts'
  6. describe('toAssistantBlock', () => {
  7. it('classifies the four block shapes', () => {
  8. const attachment = {
  9. attachmentId: AttachmentId(`sha256:${'a'.repeat(64)}`),
  10. mediaType: 'image/png' as const,
  11. bytes: 68,
  12. width: 1,
  13. height: 1,
  14. }
  15. const blocks: ContentBlock[] = [
  16. { type: 'text', text: '正文' },
  17. { type: 'reasoning', text: '思考' },
  18. { type: 'tool-call', id: 'c1', name: 'echo', arguments: '{}' } as ContentBlock,
  19. { type: 'image', attachment },
  20. ]
  21. expect(toAssistantBlocks(blocks)).toEqual([
  22. { kind: 'text', text: '正文' },
  23. { kind: 'reasoning', text: '思考' },
  24. { kind: 'tool-call', callId: 'c1', name: 'echo', argsRaw: '{}' },
  25. { kind: 'image', attachment },
  26. ])
  27. expect(toAssistantBlock(blocks[0] as ContentBlock)).toEqual({ kind: 'text', text: '正文' })
  28. })
  29. })