time-context-mock-llm.ts 899 B

12345678910111213141516171819202122
  1. import type { Context } from 'cordis'
  2. import { LlmAdapter, type StreamChunk } from '@deepseek-ai/dsh-llm'
  3. /** Deterministic one-step adapter for the time-context Loader fixture. */
  4. class TimeContextMockAdapter extends LlmAdapter {
  5. async * stream(): AsyncIterable<StreamChunk> {
  6. const text = 'time context sampled'
  7. yield { type: 'block-start', index: 0, blockType: 'text' }
  8. yield { type: 'text-delta', index: 0, text }
  9. yield { type: 'block-end', index: 0, block: { type: 'text', text } }
  10. yield { type: 'usage', usage: { inputTokens: 1, outputTokens: 1 } }
  11. yield { type: 'finish', reason: { kind: 'stop' } }
  12. }
  13. }
  14. export const name = 'time-context-mock-llm'
  15. export const inject = ['llm']
  16. /** Register the test-only `time-context-mock` adapter. */
  17. export function apply(ctx: Context): void {
  18. ctx.llm.registerAdapter(['time-context-mock'], new TimeContextMockAdapter())
  19. }