ai-test-kit 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -925,9 +925,13 @@ fromUIMessage<UIMessage>(): { UIParts; UIChunks; UIMessages }
925
925
 
926
926
  ## Types
927
927
 
928
- All types are exported from `ai-test-kit/language`.
928
+ Types are split by entry point, mirroring the builders.
929
929
 
930
- ### `MockResponse`
930
+ ### Language Models
931
+
932
+ Exported from `ai-test-kit/language`.
933
+
934
+ #### `MockResponse`
931
935
 
932
936
  A single mock response. A `string` or `Error` applies to whichever method is called; the object forms target one method explicitly. Pass an `Array<MockResponse>` to sequence responses across calls.
933
937
 
@@ -939,7 +943,7 @@ type MockResponse =
939
943
  | { generate?; stream? }; // generate and/or stream explicitly
940
944
  ```
941
945
 
942
- ### `MockLanguageModel`
946
+ #### `MockLanguageModel`
943
947
 
944
948
  The mock model instance type, as returned by `MockLanguageModel.from()`. Because the namespace and the instance type share the name, you can use `MockLanguageModel` to annotate a model parameter.
945
949
 
@@ -947,7 +951,7 @@ The mock model instance type, as returned by `MockLanguageModel.from()`. Because
947
951
  import type { MockLanguageModel } from 'ai-test-kit/language';
948
952
  ```
949
953
 
950
- ### `GenerateResponse` / `StreamResponse`
954
+ #### `GenerateResponse` / `StreamResponse`
951
955
 
952
956
  The per-method response shapes used by the `{ generate, stream }` form of `MockResponse`. `stream` accepts a bare `Array<StreamPart>`, a `ReadableStream<StreamPart>` (used as-is), or a `{ chunks, initialDelayInMs?, chunkDelayInMs? }` object to simulate delays. Both also accept a `string`, an `Error`, or a **function** of the call options returning the result directly (the escape hatch for input-dependent responses).
953
957
 
@@ -955,7 +959,7 @@ The per-method response shapes used by the `{ generate, stream }` form of `MockR
955
959
  import type { GenerateResponse, StreamResponse } from 'ai-test-kit/language';
956
960
  ```
957
961
 
958
- ### `MockLanguageModelOptions`
962
+ #### `MockLanguageModelOptions`
959
963
 
960
964
  The identity overrides accepted as the second argument to `MockLanguageModel.from()`.
961
965
 
@@ -964,7 +968,7 @@ import type { MockLanguageModelOptions } from 'ai-test-kit/language';
964
968
  // { provider?: string; modelId?: string }
965
969
  ```
966
970
 
967
- ### `StreamPartOptions`
971
+ #### `StreamPartOptions`
968
972
 
969
973
  Options for the streamed-text part builders (`StreamParts.text` / `StreamParts.reasoning`).
970
974
 
@@ -973,7 +977,7 @@ import type { StreamPartOptions } from 'ai-test-kit/language';
973
977
  // { id?: string; length?: number; separator?: string }
974
978
  ```
975
979
 
976
- ### `StreamDelayOptions`
980
+ #### `StreamDelayOptions`
977
981
 
978
982
  Simulated timing shared by `Stream.simulate`, `MockLanguageModel.streamResult`, and the `stream` chunks form. With an `abortSignal`, the stream errors with an `AbortError` the instant the signal fires (mid-delay), matching a real provider stream.
979
983
 
@@ -982,6 +986,80 @@ import type { StreamDelayOptions } from 'ai-test-kit/language';
982
986
  // { initialDelayInMs?: number | null; chunkDelayInMs?: number | null; abortSignal?: AbortSignal }
983
987
  ```
984
988
 
989
+ ### UI Messages
990
+
991
+ Exported from `ai-test-kit/ui`.
992
+
993
+ #### `UIMessageParts`
994
+
995
+ A record of every part variant of a message, keyed by its `type`; index it to pull one variant (a union key yields a union, and dynamic `tool-${name}` / `data-${name}` parts appear under their concrete names). `UIMessageParts<M>['text']` is the long form `Extract<InferUIMessagePart<M>, { type: 'text' }>`.
996
+
997
+ ```ts
998
+ import type { UIMessageParts } from 'ai-test-kit/ui';
999
+
1000
+ type TextPart = UIMessageParts<MyUIMessage>['text'];
1001
+ // { type: 'text'; text: string; state?: 'streaming' | 'done' }
1002
+
1003
+ type ToolWeatherPart = UIMessageParts<MyUIMessage>['tool-weather'];
1004
+ // { type: 'tool-weather'; toolCallId: string; state: '...'; input: ...; output: ... }
1005
+
1006
+ type TextOrReasoning = UIMessageParts<MyUIMessage>['text' | 'reasoning'];
1007
+ // TextUIPart | ReasoningUIPart
1008
+ ```
1009
+
1010
+ #### `UIMessageChunks`
1011
+
1012
+ A record of every chunk variant of a message, keyed by its `type`; index it to pull one variant (a union key yields a union). `UIMessageChunks<M>['text-start']` is the long form `Extract<InferUIMessageChunk<M>, { type: 'text-start' }>`.
1013
+
1014
+ ```ts
1015
+ import type { UIMessageChunks } from 'ai-test-kit/ui';
1016
+
1017
+ type TextStartChunk = UIMessageChunks<MyUIMessage>['text-start'];
1018
+ // { type: 'text-start'; id: string }
1019
+
1020
+ type TextChunk = UIMessageChunks<MyUIMessage>['text-start' | 'text-delta' | 'text-end'];
1021
+ // { type: 'text-start'; id: string } | { type: 'text-delta'; id: string; delta: string } | { type: 'text-end'; id: string }
1022
+ ```
1023
+
1024
+ #### `UIMessagePartOf`
1025
+
1026
+ Selects a single part variant by `type`. `TYPE` takes an exact type, a union, or a `tool-${string}` template (which the bundle can't express); a non-matching type resolves to `never`.
1027
+
1028
+ ```ts
1029
+ import type { UIMessagePartOf } from 'ai-test-kit/ui';
1030
+
1031
+ type TextPart = UIMessagePartOf<MyUIMessage, 'text'>;
1032
+ // { type: 'text'; text: string; state?: 'streaming' | 'done' }
1033
+
1034
+ type ToolParts = UIMessagePartOf<MyUIMessage, `tool-${string}`>;
1035
+ // every tool-* part of the message
1036
+ ```
1037
+
1038
+ #### `UIMessageChunkOf`
1039
+
1040
+ Selects a single chunk variant by `type`, with the same rules as `UIMessagePartOf`.
1041
+
1042
+ ```ts
1043
+ import type { UIMessageChunkOf } from 'ai-test-kit/ui';
1044
+
1045
+ type TextStartChunk = UIMessageChunkOf<MyUIMessage, 'text-start'>;
1046
+ // { type: 'text-start'; id: string }
1047
+
1048
+ type ToolChunk = UIMessageChunkOf<MyUIMessage, `tool-${string}`>;
1049
+ // every tool-* chunk of the message
1050
+ ```
1051
+
1052
+ #### `InferUIMessagePart`
1053
+
1054
+ The union of a message's parts, the part-level counterpart to the AI SDK's `InferUIMessageChunk`. The SDK ships `InferUIMessageChunk` / `InferUIMessageMetadata` / `InferUIMessageData` / `InferUIMessageTools`, but no parts inferer, so the kit adds this one.
1055
+
1056
+ ```ts
1057
+ import type { InferUIMessagePart } from 'ai-test-kit/ui';
1058
+
1059
+ type MyUIMessagePart = InferUIMessagePart<MyUIMessage>;
1060
+ // TextUIPart | ReasoningUIPart | ToolUIPart<…> | DynamicToolUIPart | SourceUrlUIPart | … (the full parts union)
1061
+ ```
1062
+
985
1063
  ## License
986
1064
 
987
1065
  MIT