()
| 6 | describe("Polling functions", () => { |
| 7 | // Create a test service with functions we can call |
| 8 | const testService = () => { |
| 9 | const client = testInstance(); |
| 10 | const prefix = `test${Math.random().toString(36).substring(2, 15)}`; |
| 11 | |
| 12 | client.register({ |
| 13 | name: `${prefix}_echo`, |
| 14 | handler: async (input: { text: string }) => { |
| 15 | return { echo: input.text }; |
| 16 | }, |
| 17 | schema: z.object({ |
| 18 | text: z.string(), |
| 19 | }), |
| 20 | }); |
| 21 | |
| 22 | client.register({ |
| 23 | name: `${prefix}_error`, |
| 24 | handler: async (_input) => { |
| 25 | throw new Error("This is an error"); |
| 26 | }, |
| 27 | schema: z.object({ |
| 28 | text: z.string(), |
| 29 | }), |
| 30 | }); |
| 31 | |
| 32 | // Register a function that takes some time to complete |
| 33 | client.register({ |
| 34 | name: `${prefix}_slow`, |
| 35 | handler: async (input: { text: string; delay: number }) => { |
| 36 | await new Promise((resolve) => setTimeout(resolve, input.delay)); |
| 37 | return { echo: input.text, delayed: true }; |
| 38 | }, |
| 39 | schema: z.object({ |
| 40 | text: z.string(), |
| 41 | delay: z.number(), |
| 42 | }), |
| 43 | }); |
| 44 | |
| 45 | // Register a function for testing invalid tools |
| 46 | client.register({ |
| 47 | name: `${prefix}_valid`, |
| 48 | handler: async (input: { text: string }) => { |
| 49 | return { success: true, text: input.text }; |
| 50 | }, |
| 51 | schema: z.object({ |
| 52 | text: z.string(), |
| 53 | }), |
| 54 | }); |
| 55 | |
| 56 | return { |
| 57 | client, |
| 58 | prefix, |
| 59 | }; |
| 60 | }; |
| 61 | |
| 62 | // Set up our test service |
| 63 | const service = testService(); |
no test coverage detected