Commit 89d085a
authored
fix(references): repair ai-chat typecheck against current wire shape (#3685)
## Summary
Pre-existing typecheck errors in `references/ai-chat` against the
current SDK shape. Unblocks `pnpm exec tsc --noEmit` in the reference
project.
## What changed
Three categories of fixes inside `references/ai-chat`. No SDK changes.
### 1. `payload.messages` → `payload.message`
The wire payload is now delta-only — one new message per trigger,
optional. Old code in two raw-task files reads `payload.messages`
(plural array) which no longer exists.
```ts
// before
const messages = await conversation.addIncoming(currentPayload.messages, ...);
// after
const messages = await conversation.addIncoming(
currentPayload.message ? [currentPayload.message] : [],
...
);
```
Same fix to the `chat.messages.on` handler, reading `msg.message`
(singular) instead of `msg.messages[length - 1]`.
### 2. `clientData` non-null assertion in `cf-trust-test`
`ChatTurnContext.clientData` is typed as `?: TClientData` on
`onTurnStart` / `run` event objects even when the agent declares a
`clientDataSchema`. The runtime validates against the schema before the
hook fires, so it's structurally non-null — but TypeScript can't know
that. Non-null assert for now.
Follow-up worth filing: narrow `ChatTurnContext.clientData` to
non-optional when the agent has a `clientDataSchema`. Same friction the
docs friction-test subagent flagged.
### 3. `stress-emit.parseConfig` retyped against `ModelMessage[]`
The `run` callback hands `messages: ModelMessage[]`, not `UIMessage[]`.
Update `parseConfig` to accept `ModelMessage[]` and pull text from
`content` (string or array-of-parts).
## Test plan
- [x] `pnpm exec tsc --noEmit` in `references/ai-chat` passes (was 8
errors, now 0)1 parent 9ff410b commit 89d085a
3 files changed
Lines changed: 15 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
275 | | - | |
| 275 | + | |
276 | 276 | | |
277 | 277 | | |
278 | 278 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
662 | | - | |
| 662 | + | |
663 | 663 | | |
664 | 664 | | |
665 | 665 | | |
| |||
678 | 678 | | |
679 | 679 | | |
680 | 680 | | |
681 | | - | |
682 | | - | |
| 681 | + | |
683 | 682 | | |
684 | 683 | | |
685 | 684 | | |
| |||
1049 | 1048 | | |
1050 | 1049 | | |
1051 | 1050 | | |
1052 | | - | |
| 1051 | + | |
1053 | 1052 | | |
1054 | 1053 | | |
1055 | | - | |
| 1054 | + | |
1056 | 1055 | | |
1057 | 1056 | | |
1058 | 1057 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| |||
0 commit comments