event-script.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Minimal SessionEvent builders for orchestration tests (shape mirrors what the
  2. // host emits; only the fields the object layer reads).
  3. import type { ContentBlock } from '@deepseek-ai/dsh-llm/types'
  4. import type { SessionEvent } from '@deepseek-ai/dsh-session/types'
  5. /** One text content block (local helper). */
  6. const text = (t: string): ContentBlock[] => [{ type: 'text', text: t }]
  7. const at = (seq: number, e: Record<string, unknown>): SessionEvent =>
  8. ({ seq, time: 1_700_000_000_000 + seq, ...e }) as unknown as SessionEvent
  9. export const ev = {
  10. turnStart: (seq: number, turn: number): SessionEvent =>
  11. at(seq, { type: 'turn/start', data: { turn, trigger: { kind: 'message', source: { kind: 'user' } } } }),
  12. user: (seq: number, body: string): SessionEvent =>
  13. at(seq, { type: 'user/message', surfaceOp: 'append', data: { content: text(body), source: { kind: 'user' } } }),
  14. stepStart: (seq: number, turn: number, step = 0): SessionEvent =>
  15. at(seq, { type: 'step/start', data: { turn, step } }),
  16. chunkStart: (seq: number, turn: number, step = 0, index = 0): SessionEvent =>
  17. at(seq, { type: 'assistant/chunk', data: { turn, step, chunk: { type: 'block-start', index, blockType: 'text' } } }),
  18. chunkText: (seq: number, turn: number, piece: string, step = 0, index = 0): SessionEvent =>
  19. at(seq, { type: 'assistant/chunk', data: { turn, step, chunk: { type: 'text-delta', index, text: piece } } }),
  20. assistant: (seq: number, turn: number, body: string, step = 0): SessionEvent =>
  21. at(seq, { type: 'assistant/message', surfaceOp: 'append', data: { turn, step, content: text(body), provenance: { provider: 'fake', model: 'fk-1' } } }),
  22. toolCall: (seq: number, turn: number, callId: string, name: string, args: string, step = 0): SessionEvent =>
  23. at(seq, { type: 'tool/call', data: { turn, step, callId, name, arguments: args } }),
  24. toolResult: (seq: number, turn: number, callId: string, body: string, step = 0): SessionEvent =>
  25. at(seq, { type: 'tool/result', surfaceOp: 'append', data: { turn, step, callId, content: text(body), isError: false } }),
  26. stepEnd: (seq: number, turn: number, step = 0): SessionEvent =>
  27. at(seq, { type: 'step/end', data: { turn, step } }),
  28. turnEnd: (seq: number, turn: number, reason: 'completed' | 'cancelled' = 'completed'): SessionEvent =>
  29. at(seq, { type: 'turn/end', data: { turn, reason: { kind: reason } } }),
  30. }
  31. /** One complete plain turn (turn/start → user → step → assistant → turn/end), 6 events from startSeq. */
  32. export function plainTurn(startSeq: number, turn: number, ask: string, answer: string): SessionEvent[] {
  33. return [
  34. ev.turnStart(startSeq, turn),
  35. ev.user(startSeq + 1, ask),
  36. ev.stepStart(startSeq + 2, turn),
  37. ev.assistant(startSeq + 3, turn, answer),
  38. ev.stepEnd(startSeq + 4, turn),
  39. ev.turnEnd(startSeq + 5, turn),
  40. ]
  41. }
  42. /** Wrap raw events as view-less history entries (the wire shape history now returns). */
  43. export function entries(events: readonly SessionEvent[]): { event: SessionEvent }[] {
  44. return events.map(event => ({ event }))
  45. }