MCPcopy
hub / github.com/TanStack/ai / textTurn

Function textTurn

packages/ai/tests/chat-structured-output-null-normalization.test.ts:43–68  ·  view source on GitHub ↗

A native-combined turn: the schema-constrained JSON arrives as assistant text.

(json: string)

Source from the content-addressed store, hash-verified

41
42/** A native-combined turn: the schema-constrained JSON arrives as assistant text. */
43function textTurn(json: string): Array<StreamChunk> {
44 const timestamp = Date.now()
45 return [
46 { type: EventType.RUN_STARTED, runId: 'r1', threadId: 't1', timestamp },
47 {
48 type: EventType.TEXT_MESSAGE_START,
49 messageId: 'm1',
50 role: 'assistant',
51 timestamp,
52 },
53 {
54 type: EventType.TEXT_MESSAGE_CONTENT,
55 messageId: 'm1',
56 delta: json,
57 timestamp,
58 },
59 { type: EventType.TEXT_MESSAGE_END, messageId: 'm1', timestamp },
60 {
61 type: EventType.RUN_FINISHED,
62 runId: 'r1',
63 threadId: 't1',
64 finishReason: 'stop',
65 timestamp,
66 },
67 ] as Array<StreamChunk>
68}
69
70describe('structured output null normalization', () => {
71 it('drops a provider null for an optional field so validation passes', async () => {

Calls 1

nowMethod · 0.80

Tested by

no test coverage detected