@ai-sdk/provider-utils 4.0.6 → 4.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/provider-utils",
3
- "version": "4.0.6",
3
+ "version": "4.0.8",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@standard-schema/spec": "^1.1.0",
33
33
  "eventsource-parser": "^3.0.6",
34
- "@ai-sdk/provider": "3.0.3"
34
+ "@ai-sdk/provider": "3.0.4"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "20.17.24",
@@ -31,6 +31,41 @@ describe('tool type', () => {
31
31
  expectTypeOf(aTool.execute).not.toEqualTypeOf<Function>();
32
32
  expectTypeOf(aTool.inputSchema).toEqualTypeOf<FlexibleSchema<T>>();
33
33
  });
34
+
35
+ it('should infer input type correctly when inputExamples are present with optional/default zod schema', () => {
36
+ const inputSchema = z.object({
37
+ location: z.string(),
38
+ unit: z.enum(['celsius', 'fahrenheit']).optional().default('celsius'),
39
+ });
40
+
41
+ tool({
42
+ description: 'Get the weather for a location',
43
+ inputSchema,
44
+ inputExamples: [
45
+ { input: { location: 'San Francisco', unit: 'celsius' } },
46
+ ],
47
+ execute: async input => {
48
+ expectTypeOf(input).toEqualTypeOf<z.infer<typeof inputSchema>>();
49
+ return { temperature: 20, unit: input.unit };
50
+ },
51
+ });
52
+ });
53
+
54
+ it('should infer input type correctly when inputExamples are present with refine zod schema', () => {
55
+ const inputSchema = z.object({
56
+ code: z.string().refine(val => val.length === 3),
57
+ });
58
+
59
+ tool({
60
+ description: 'Get code details',
61
+ inputSchema,
62
+ inputExamples: [{ input: { code: 'ABC' } }],
63
+ execute: async input => {
64
+ expectTypeOf(input).toEqualTypeOf<z.infer<typeof inputSchema>>();
65
+ return { valid: true };
66
+ },
67
+ });
68
+ });
34
69
  });
35
70
 
36
71
  describe('output type', () => {
package/src/types/tool.ts CHANGED
@@ -141,7 +141,7 @@ functionality that can be fully encapsulated in the provider.
141
141
  * An optional list of input examples that show the language
142
142
  * model what the input should look like.
143
143
  */
144
- inputExamples?: Array<{ input: INPUT }>;
144
+ inputExamples?: Array<{ input: NoInfer<INPUT> }>;
145
145
 
146
146
  /**
147
147
  * Whether the tool needs approval before it can be executed.