ai 5.0.0-canary.4 → 5.0.0-canary.6
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/CHANGELOG.md +18 -0
 - package/dist/index.d.mts +861 -145
 - package/dist/index.d.ts +861 -145
 - package/dist/index.js +1653 -166
 - package/dist/index.js.map +1 -1
 - package/dist/index.mjs +1568 -119
 - package/dist/index.mjs.map +1 -1
 - package/dist/internal/index.d.mts +205 -15
 - package/dist/internal/index.d.ts +205 -15
 - package/dist/internal/index.js +63 -9
 - package/dist/internal/index.js.map +1 -1
 - package/dist/internal/index.mjs +46 -2
 - package/dist/internal/index.mjs.map +1 -1
 - package/dist/mcp-stdio/index.js.map +1 -0
 - package/dist/mcp-stdio/index.mjs.map +1 -0
 - package/dist/test/index.js.map +1 -0
 - package/dist/test/index.mjs.map +1 -0
 - package/package.json +18 -19
 - package/mcp-stdio/create-child-process.test.ts +0 -92
 - package/mcp-stdio/create-child-process.ts +0 -21
 - package/mcp-stdio/dist/index.js.map +0 -1
 - package/mcp-stdio/dist/index.mjs.map +0 -1
 - package/mcp-stdio/get-environment.test.ts +0 -13
 - package/mcp-stdio/get-environment.ts +0 -43
 - package/mcp-stdio/index.ts +0 -4
 - package/mcp-stdio/mcp-stdio-transport.test.ts +0 -262
 - package/mcp-stdio/mcp-stdio-transport.ts +0 -157
 - package/test/dist/index.js.map +0 -1
 - package/test/dist/index.mjs.map +0 -1
 - package/{mcp-stdio/dist → dist/mcp-stdio}/index.d.mts +6 -6
 - package/{mcp-stdio/dist → dist/mcp-stdio}/index.d.ts +6 -6
 - /package/{mcp-stdio/dist → dist/mcp-stdio}/index.js +0 -0
 - /package/{mcp-stdio/dist → dist/mcp-stdio}/index.mjs +0 -0
 - /package/{test/dist → dist/test}/index.d.mts +0 -0
 - /package/{test/dist → dist/test}/index.d.ts +0 -0
 - /package/{test/dist → dist/test}/index.js +0 -0
 - /package/{test/dist → dist/test}/index.mjs +0 -0
 
| 
         @@ -1,262 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import type { ChildProcess } from 'node:child_process';
         
     | 
| 
       2 
     | 
    
         
            -
            import { EventEmitter } from 'node:events';
         
     | 
| 
       3 
     | 
    
         
            -
            import { beforeEach, describe, expect, it, vi } from 'vitest';
         
     | 
| 
       4 
     | 
    
         
            -
            import { JSONRPCMessage } from '../core/tool/mcp/json-rpc-message';
         
     | 
| 
       5 
     | 
    
         
            -
            import { MCPClientError } from '../errors';
         
     | 
| 
       6 
     | 
    
         
            -
            import { createChildProcess } from './create-child-process';
         
     | 
| 
       7 
     | 
    
         
            -
            import { StdioMCPTransport } from './mcp-stdio-transport';
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
            vi.mock('./create-child-process', { spy: true });
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            interface MockChildProcess {
         
     | 
| 
       12 
     | 
    
         
            -
              stdin: EventEmitter & { write?: ReturnType<typeof vi.fn> };
         
     | 
| 
       13 
     | 
    
         
            -
              stdout: EventEmitter;
         
     | 
| 
       14 
     | 
    
         
            -
              stderr: EventEmitter;
         
     | 
| 
       15 
     | 
    
         
            -
              on: ReturnType<typeof vi.fn>;
         
     | 
| 
       16 
     | 
    
         
            -
              removeAllListeners: ReturnType<typeof vi.fn>;
         
     | 
| 
       17 
     | 
    
         
            -
            }
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            describe('StdioMCPTransport', () => {
         
     | 
| 
       20 
     | 
    
         
            -
              let transport: StdioMCPTransport;
         
     | 
| 
       21 
     | 
    
         
            -
              let mockChildProcess: MockChildProcess;
         
     | 
| 
       22 
     | 
    
         
            -
              let mockStdin: EventEmitter & { write?: ReturnType<typeof vi.fn> };
         
     | 
| 
       23 
     | 
    
         
            -
              let mockStdout: EventEmitter;
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
              beforeEach(() => {
         
     | 
| 
       26 
     | 
    
         
            -
                vi.clearAllMocks();
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                mockStdin = new EventEmitter();
         
     | 
| 
       29 
     | 
    
         
            -
                mockStdout = new EventEmitter();
         
     | 
| 
       30 
     | 
    
         
            -
                mockChildProcess = {
         
     | 
| 
       31 
     | 
    
         
            -
                  stdin: mockStdin,
         
     | 
| 
       32 
     | 
    
         
            -
                  stdout: mockStdout,
         
     | 
| 
       33 
     | 
    
         
            -
                  stderr: new EventEmitter(),
         
     | 
| 
       34 
     | 
    
         
            -
                  on: vi.fn(),
         
     | 
| 
       35 
     | 
    
         
            -
                  removeAllListeners: vi.fn(),
         
     | 
| 
       36 
     | 
    
         
            -
                };
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                vi.mocked(createChildProcess).mockResolvedValue(
         
     | 
| 
       39 
     | 
    
         
            -
                  mockChildProcess as unknown as ChildProcess,
         
     | 
| 
       40 
     | 
    
         
            -
                );
         
     | 
| 
       41 
     | 
    
         
            -
             
     | 
| 
       42 
     | 
    
         
            -
                transport = new StdioMCPTransport({
         
     | 
| 
       43 
     | 
    
         
            -
                  command: 'test-command',
         
     | 
| 
       44 
     | 
    
         
            -
                  args: ['--test'],
         
     | 
| 
       45 
     | 
    
         
            -
                });
         
     | 
| 
       46 
     | 
    
         
            -
              });
         
     | 
| 
       47 
     | 
    
         
            -
             
     | 
| 
       48 
     | 
    
         
            -
              afterEach(() => {
         
     | 
| 
       49 
     | 
    
         
            -
                transport.close();
         
     | 
| 
       50 
     | 
    
         
            -
              });
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
              describe('start', () => {
         
     | 
| 
       53 
     | 
    
         
            -
                it('should successfully start the transport', async () => {
         
     | 
| 
       54 
     | 
    
         
            -
                  const stdinOnSpy = vi.spyOn(mockStdin, 'on');
         
     | 
| 
       55 
     | 
    
         
            -
                  const stdoutOnSpy = vi.spyOn(mockStdout, 'on');
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                  mockChildProcess.on.mockImplementation(
         
     | 
| 
       58 
     | 
    
         
            -
                    (event: string, callback: () => void) => {
         
     | 
| 
       59 
     | 
    
         
            -
                      if (event === 'spawn') {
         
     | 
| 
       60 
     | 
    
         
            -
                        callback();
         
     | 
| 
       61 
     | 
    
         
            -
                      }
         
     | 
| 
       62 
     | 
    
         
            -
                    },
         
     | 
| 
       63 
     | 
    
         
            -
                  );
         
     | 
| 
       64 
     | 
    
         
            -
             
     | 
| 
       65 
     | 
    
         
            -
                  const startPromise = transport.start();
         
     | 
| 
       66 
     | 
    
         
            -
                  await expect(startPromise).resolves.toBeUndefined();
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                  expect(mockChildProcess.on).toHaveBeenCalledWith(
         
     | 
| 
       69 
     | 
    
         
            -
                    'error',
         
     | 
| 
       70 
     | 
    
         
            -
                    expect.any(Function),
         
     | 
| 
       71 
     | 
    
         
            -
                  );
         
     | 
| 
       72 
     | 
    
         
            -
                  expect(mockChildProcess.on).toHaveBeenCalledWith(
         
     | 
| 
       73 
     | 
    
         
            -
                    'spawn',
         
     | 
| 
       74 
     | 
    
         
            -
                    expect.any(Function),
         
     | 
| 
       75 
     | 
    
         
            -
                  );
         
     | 
| 
       76 
     | 
    
         
            -
                  expect(mockChildProcess.on).toHaveBeenCalledWith(
         
     | 
| 
       77 
     | 
    
         
            -
                    'close',
         
     | 
| 
       78 
     | 
    
         
            -
                    expect.any(Function),
         
     | 
| 
       79 
     | 
    
         
            -
                  );
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                  expect(stdinOnSpy).toHaveBeenCalledWith('error', expect.any(Function));
         
     | 
| 
       82 
     | 
    
         
            -
                  expect(stdoutOnSpy).toHaveBeenCalledWith('error', expect.any(Function));
         
     | 
| 
       83 
     | 
    
         
            -
                  expect(stdoutOnSpy).toHaveBeenCalledWith('data', expect.any(Function));
         
     | 
| 
       84 
     | 
    
         
            -
                });
         
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
                it('should throw error if already started', async () => {
         
     | 
| 
       87 
     | 
    
         
            -
                  mockChildProcess.on.mockImplementation(
         
     | 
| 
       88 
     | 
    
         
            -
                    (event: string, callback: () => void) => {
         
     | 
| 
       89 
     | 
    
         
            -
                      if (event === 'spawn') {
         
     | 
| 
       90 
     | 
    
         
            -
                        callback();
         
     | 
| 
       91 
     | 
    
         
            -
                      }
         
     | 
| 
       92 
     | 
    
         
            -
                    },
         
     | 
| 
       93 
     | 
    
         
            -
                  );
         
     | 
| 
       94 
     | 
    
         
            -
                  const firstStart = transport.start();
         
     | 
| 
       95 
     | 
    
         
            -
                  await expect(firstStart).resolves.toBeUndefined();
         
     | 
| 
       96 
     | 
    
         
            -
                  const secondStart = transport.start();
         
     | 
| 
       97 
     | 
    
         
            -
                  await expect(secondStart).rejects.toThrow(MCPClientError);
         
     | 
| 
       98 
     | 
    
         
            -
                });
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                it('should handle spawn errors', async () => {
         
     | 
| 
       101 
     | 
    
         
            -
                  const error = new Error('Spawn failed');
         
     | 
| 
       102 
     | 
    
         
            -
                  const onErrorSpy = vi.fn();
         
     | 
| 
       103 
     | 
    
         
            -
                  transport.onerror = onErrorSpy;
         
     | 
| 
       104 
     | 
    
         
            -
             
     | 
| 
       105 
     | 
    
         
            -
                  // simulate `spawn` failure by emitting error event after returning child process
         
     | 
| 
       106 
     | 
    
         
            -
                  mockChildProcess.on.mockImplementation(
         
     | 
| 
       107 
     | 
    
         
            -
                    (event: string, callback: (err: Error) => void) => {
         
     | 
| 
       108 
     | 
    
         
            -
                      if (event === 'error') {
         
     | 
| 
       109 
     | 
    
         
            -
                        callback(error);
         
     | 
| 
       110 
     | 
    
         
            -
                      }
         
     | 
| 
       111 
     | 
    
         
            -
                    },
         
     | 
| 
       112 
     | 
    
         
            -
                  );
         
     | 
| 
       113 
     | 
    
         
            -
             
     | 
| 
       114 
     | 
    
         
            -
                  const startPromise = transport.start();
         
     | 
| 
       115 
     | 
    
         
            -
                  await expect(startPromise).rejects.toThrow('Spawn failed');
         
     | 
| 
       116 
     | 
    
         
            -
                  expect(onErrorSpy).toHaveBeenCalledWith(error);
         
     | 
| 
       117 
     | 
    
         
            -
                });
         
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
                it('should handle child_process import errors', async () => {
         
     | 
| 
       120 
     | 
    
         
            -
                  vi.mocked(createChildProcess).mockRejectedValue(
         
     | 
| 
       121 
     | 
    
         
            -
                    new MCPClientError({
         
     | 
| 
       122 
     | 
    
         
            -
                      message: 'Failed to load child_process module dynamically',
         
     | 
| 
       123 
     | 
    
         
            -
                    }),
         
     | 
| 
       124 
     | 
    
         
            -
                  );
         
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
                  const startPromise = transport.start();
         
     | 
| 
       127 
     | 
    
         
            -
                  await expect(startPromise).rejects.toThrow(
         
     | 
| 
       128 
     | 
    
         
            -
                    'Failed to load child_process module dynamically',
         
     | 
| 
       129 
     | 
    
         
            -
                  );
         
     | 
| 
       130 
     | 
    
         
            -
                });
         
     | 
| 
       131 
     | 
    
         
            -
              });
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
              describe('send', () => {
         
     | 
| 
       134 
     | 
    
         
            -
                beforeEach(async () => {
         
     | 
| 
       135 
     | 
    
         
            -
                  mockChildProcess.on.mockImplementation(
         
     | 
| 
       136 
     | 
    
         
            -
                    (event: string, callback: () => void) => {
         
     | 
| 
       137 
     | 
    
         
            -
                      if (event === 'spawn') {
         
     | 
| 
       138 
     | 
    
         
            -
                        callback();
         
     | 
| 
       139 
     | 
    
         
            -
                      }
         
     | 
| 
       140 
     | 
    
         
            -
                    },
         
     | 
| 
       141 
     | 
    
         
            -
                  );
         
     | 
| 
       142 
     | 
    
         
            -
                  await transport.start();
         
     | 
| 
       143 
     | 
    
         
            -
                });
         
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
                it('should successfully send a message', async () => {
         
     | 
| 
       146 
     | 
    
         
            -
                  const message: JSONRPCMessage = {
         
     | 
| 
       147 
     | 
    
         
            -
                    jsonrpc: '2.0',
         
     | 
| 
       148 
     | 
    
         
            -
                    id: '1',
         
     | 
| 
       149 
     | 
    
         
            -
                    method: 'test',
         
     | 
| 
       150 
     | 
    
         
            -
                    params: {},
         
     | 
| 
       151 
     | 
    
         
            -
                  };
         
     | 
| 
       152 
     | 
    
         
            -
             
     | 
| 
       153 
     | 
    
         
            -
                  mockStdin.write = vi.fn().mockReturnValue(true);
         
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
                  await transport.send(message);
         
     | 
| 
       156 
     | 
    
         
            -
             
     | 
| 
       157 
     | 
    
         
            -
                  expect(mockStdin.write).toHaveBeenCalledWith(
         
     | 
| 
       158 
     | 
    
         
            -
                    JSON.stringify(message) + '\n',
         
     | 
| 
       159 
     | 
    
         
            -
                  );
         
     | 
| 
       160 
     | 
    
         
            -
                });
         
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       162 
     | 
    
         
            -
                it('should handle write backpressure', async () => {
         
     | 
| 
       163 
     | 
    
         
            -
                  const message: JSONRPCMessage = {
         
     | 
| 
       164 
     | 
    
         
            -
                    jsonrpc: '2.0',
         
     | 
| 
       165 
     | 
    
         
            -
                    id: '1',
         
     | 
| 
       166 
     | 
    
         
            -
                    method: 'test',
         
     | 
| 
       167 
     | 
    
         
            -
                    params: {},
         
     | 
| 
       168 
     | 
    
         
            -
                  };
         
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
                  mockStdin.write = vi.fn().mockReturnValue(false);
         
     | 
| 
       171 
     | 
    
         
            -
             
     | 
| 
       172 
     | 
    
         
            -
                  const sendPromise = transport.send(message);
         
     | 
| 
       173 
     | 
    
         
            -
             
     | 
| 
       174 
     | 
    
         
            -
                  mockStdin.emit('drain');
         
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
                  await expect(sendPromise).resolves.toBeUndefined();
         
     | 
| 
       177 
     | 
    
         
            -
                });
         
     | 
| 
       178 
     | 
    
         
            -
             
     | 
| 
       179 
     | 
    
         
            -
                it('should throw error if transport is not connected', async () => {
         
     | 
| 
       180 
     | 
    
         
            -
                  await transport.close();
         
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
                  const message: JSONRPCMessage = {
         
     | 
| 
       183 
     | 
    
         
            -
                    jsonrpc: '2.0',
         
     | 
| 
       184 
     | 
    
         
            -
                    id: '1',
         
     | 
| 
       185 
     | 
    
         
            -
                    method: 'test',
         
     | 
| 
       186 
     | 
    
         
            -
                    params: {},
         
     | 
| 
       187 
     | 
    
         
            -
                  };
         
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
                  await expect(transport.send(message)).rejects.toThrow(MCPClientError);
         
     | 
| 
       190 
     | 
    
         
            -
                });
         
     | 
| 
       191 
     | 
    
         
            -
              });
         
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
       193 
     | 
    
         
            -
              describe('message handling', () => {
         
     | 
| 
       194 
     | 
    
         
            -
                const onMessageSpy = vi.fn();
         
     | 
| 
       195 
     | 
    
         
            -
             
     | 
| 
       196 
     | 
    
         
            -
                beforeEach(async () => {
         
     | 
| 
       197 
     | 
    
         
            -
                  mockChildProcess.on.mockImplementation(
         
     | 
| 
       198 
     | 
    
         
            -
                    (event: string, callback: () => void) => {
         
     | 
| 
       199 
     | 
    
         
            -
                      if (event === 'spawn') {
         
     | 
| 
       200 
     | 
    
         
            -
                        callback();
         
     | 
| 
       201 
     | 
    
         
            -
                      }
         
     | 
| 
       202 
     | 
    
         
            -
                    },
         
     | 
| 
       203 
     | 
    
         
            -
                  );
         
     | 
| 
       204 
     | 
    
         
            -
                  transport.onmessage = onMessageSpy;
         
     | 
| 
       205 
     | 
    
         
            -
                  await transport.start();
         
     | 
| 
       206 
     | 
    
         
            -
                });
         
     | 
| 
       207 
     | 
    
         
            -
             
     | 
| 
       208 
     | 
    
         
            -
                it('should handle incoming messages correctly', async () => {
         
     | 
| 
       209 
     | 
    
         
            -
                  const message: JSONRPCMessage = {
         
     | 
| 
       210 
     | 
    
         
            -
                    jsonrpc: '2.0',
         
     | 
| 
       211 
     | 
    
         
            -
                    id: '1',
         
     | 
| 
       212 
     | 
    
         
            -
                    method: 'test',
         
     | 
| 
       213 
     | 
    
         
            -
                    params: {},
         
     | 
| 
       214 
     | 
    
         
            -
                  };
         
     | 
| 
       215 
     | 
    
         
            -
             
     | 
| 
       216 
     | 
    
         
            -
                  mockStdout.emit('data', Buffer.from(JSON.stringify(message) + '\n'));
         
     | 
| 
       217 
     | 
    
         
            -
                  expect(onMessageSpy).toHaveBeenCalledWith(message);
         
     | 
| 
       218 
     | 
    
         
            -
                });
         
     | 
| 
       219 
     | 
    
         
            -
             
     | 
| 
       220 
     | 
    
         
            -
                it('should handle partial messages correctly', async () => {
         
     | 
| 
       221 
     | 
    
         
            -
                  const message = {
         
     | 
| 
       222 
     | 
    
         
            -
                    jsonrpc: '2.0',
         
     | 
| 
       223 
     | 
    
         
            -
                    id: '1',
         
     | 
| 
       224 
     | 
    
         
            -
                    method: 'test',
         
     | 
| 
       225 
     | 
    
         
            -
                    params: {},
         
     | 
| 
       226 
     | 
    
         
            -
                  };
         
     | 
| 
       227 
     | 
    
         
            -
             
     | 
| 
       228 
     | 
    
         
            -
                  const messageStr = JSON.stringify(message);
         
     | 
| 
       229 
     | 
    
         
            -
                  mockStdout.emit('data', Buffer.from(messageStr.slice(0, 10)));
         
     | 
| 
       230 
     | 
    
         
            -
                  mockStdout.emit('data', Buffer.from(messageStr.slice(10) + '\n'));
         
     | 
| 
       231 
     | 
    
         
            -
                  expect(onMessageSpy).toHaveBeenCalledWith(message);
         
     | 
| 
       232 
     | 
    
         
            -
                });
         
     | 
| 
       233 
     | 
    
         
            -
              });
         
     | 
| 
       234 
     | 
    
         
            -
             
     | 
| 
       235 
     | 
    
         
            -
              describe('close', () => {
         
     | 
| 
       236 
     | 
    
         
            -
                const onCloseSpy = vi.fn();
         
     | 
| 
       237 
     | 
    
         
            -
             
     | 
| 
       238 
     | 
    
         
            -
                beforeEach(async () => {
         
     | 
| 
       239 
     | 
    
         
            -
                  mockChildProcess.on.mockImplementation(
         
     | 
| 
       240 
     | 
    
         
            -
                    (event: string, callback: (code?: number) => void) => {
         
     | 
| 
       241 
     | 
    
         
            -
                      if (event === 'spawn') {
         
     | 
| 
       242 
     | 
    
         
            -
                        callback();
         
     | 
| 
       243 
     | 
    
         
            -
                      } else if (event === 'close') {
         
     | 
| 
       244 
     | 
    
         
            -
                        callback(0);
         
     | 
| 
       245 
     | 
    
         
            -
                      }
         
     | 
| 
       246 
     | 
    
         
            -
                    },
         
     | 
| 
       247 
     | 
    
         
            -
                  );
         
     | 
| 
       248 
     | 
    
         
            -
                  transport.onclose = onCloseSpy;
         
     | 
| 
       249 
     | 
    
         
            -
                  await transport.start();
         
     | 
| 
       250 
     | 
    
         
            -
                });
         
     | 
| 
       251 
     | 
    
         
            -
             
     | 
| 
       252 
     | 
    
         
            -
                it('should close the transport successfully', async () => {
         
     | 
| 
       253 
     | 
    
         
            -
                  await transport.close();
         
     | 
| 
       254 
     | 
    
         
            -
             
     | 
| 
       255 
     | 
    
         
            -
                  expect(mockChildProcess.on).toHaveBeenCalledWith(
         
     | 
| 
       256 
     | 
    
         
            -
                    'close',
         
     | 
| 
       257 
     | 
    
         
            -
                    expect.any(Function),
         
     | 
| 
       258 
     | 
    
         
            -
                  );
         
     | 
| 
       259 
     | 
    
         
            -
                  expect(onCloseSpy).toHaveBeenCalled();
         
     | 
| 
       260 
     | 
    
         
            -
                });
         
     | 
| 
       261 
     | 
    
         
            -
              });
         
     | 
| 
       262 
     | 
    
         
            -
            });
         
     | 
| 
         @@ -1,157 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            import type { ChildProcess, IOType } from 'node:child_process';
         
     | 
| 
       2 
     | 
    
         
            -
            import { Stream } from 'node:stream';
         
     | 
| 
       3 
     | 
    
         
            -
            import {
         
     | 
| 
       4 
     | 
    
         
            -
              JSONRPCMessage,
         
     | 
| 
       5 
     | 
    
         
            -
              JSONRPCMessageSchema,
         
     | 
| 
       6 
     | 
    
         
            -
            } from '../core/tool/mcp/json-rpc-message';
         
     | 
| 
       7 
     | 
    
         
            -
            import { MCPTransport } from '../core/tool/mcp/mcp-transport';
         
     | 
| 
       8 
     | 
    
         
            -
            import { MCPClientError } from '../errors';
         
     | 
| 
       9 
     | 
    
         
            -
            import { createChildProcess } from './create-child-process';
         
     | 
| 
       10 
     | 
    
         
            -
             
     | 
| 
       11 
     | 
    
         
            -
            export interface StdioConfig {
         
     | 
| 
       12 
     | 
    
         
            -
              command: string;
         
     | 
| 
       13 
     | 
    
         
            -
              args?: string[];
         
     | 
| 
       14 
     | 
    
         
            -
              env?: Record<string, string>;
         
     | 
| 
       15 
     | 
    
         
            -
              stderr?: IOType | Stream | number;
         
     | 
| 
       16 
     | 
    
         
            -
              cwd?: string;
         
     | 
| 
       17 
     | 
    
         
            -
            }
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
            export class StdioMCPTransport implements MCPTransport {
         
     | 
| 
       20 
     | 
    
         
            -
              private process?: ChildProcess;
         
     | 
| 
       21 
     | 
    
         
            -
              private abortController: AbortController = new AbortController();
         
     | 
| 
       22 
     | 
    
         
            -
              private readBuffer: ReadBuffer = new ReadBuffer();
         
     | 
| 
       23 
     | 
    
         
            -
              private serverParams: StdioConfig;
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
              onclose?: () => void;
         
     | 
| 
       26 
     | 
    
         
            -
              onerror?: (error: unknown) => void;
         
     | 
| 
       27 
     | 
    
         
            -
              onmessage?: (message: JSONRPCMessage) => void;
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
              constructor(server: StdioConfig) {
         
     | 
| 
       30 
     | 
    
         
            -
                this.serverParams = server;
         
     | 
| 
       31 
     | 
    
         
            -
              }
         
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
              async start(): Promise<void> {
         
     | 
| 
       34 
     | 
    
         
            -
                if (this.process) {
         
     | 
| 
       35 
     | 
    
         
            -
                  throw new MCPClientError({
         
     | 
| 
       36 
     | 
    
         
            -
                    message: 'StdioMCPTransport already started.',
         
     | 
| 
       37 
     | 
    
         
            -
                  });
         
     | 
| 
       38 
     | 
    
         
            -
                }
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                return new Promise(async (resolve, reject) => {
         
     | 
| 
       41 
     | 
    
         
            -
                  try {
         
     | 
| 
       42 
     | 
    
         
            -
                    const process = await createChildProcess(
         
     | 
| 
       43 
     | 
    
         
            -
                      this.serverParams,
         
     | 
| 
       44 
     | 
    
         
            -
                      this.abortController.signal,
         
     | 
| 
       45 
     | 
    
         
            -
                    );
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
                    this.process = process;
         
     | 
| 
       48 
     | 
    
         
            -
             
     | 
| 
       49 
     | 
    
         
            -
                    this.process.on('error', error => {
         
     | 
| 
       50 
     | 
    
         
            -
                      if (error.name === 'AbortError') {
         
     | 
| 
       51 
     | 
    
         
            -
                        this.onclose?.();
         
     | 
| 
       52 
     | 
    
         
            -
                        return;
         
     | 
| 
       53 
     | 
    
         
            -
                      }
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                      reject(error);
         
     | 
| 
       56 
     | 
    
         
            -
                      this.onerror?.(error);
         
     | 
| 
       57 
     | 
    
         
            -
                    });
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                    this.process.on('spawn', () => {
         
     | 
| 
       60 
     | 
    
         
            -
                      resolve();
         
     | 
| 
       61 
     | 
    
         
            -
                    });
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                    this.process.on('close', _code => {
         
     | 
| 
       64 
     | 
    
         
            -
                      this.process = undefined;
         
     | 
| 
       65 
     | 
    
         
            -
                      this.onclose?.();
         
     | 
| 
       66 
     | 
    
         
            -
                    });
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                    this.process.stdin?.on('error', error => {
         
     | 
| 
       69 
     | 
    
         
            -
                      this.onerror?.(error);
         
     | 
| 
       70 
     | 
    
         
            -
                    });
         
     | 
| 
       71 
     | 
    
         
            -
             
     | 
| 
       72 
     | 
    
         
            -
                    this.process.stdout?.on('data', chunk => {
         
     | 
| 
       73 
     | 
    
         
            -
                      this.readBuffer.append(chunk);
         
     | 
| 
       74 
     | 
    
         
            -
                      this.processReadBuffer();
         
     | 
| 
       75 
     | 
    
         
            -
                    });
         
     | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
                    this.process.stdout?.on('error', error => {
         
     | 
| 
       78 
     | 
    
         
            -
                      this.onerror?.(error);
         
     | 
| 
       79 
     | 
    
         
            -
                    });
         
     | 
| 
       80 
     | 
    
         
            -
                  } catch (error) {
         
     | 
| 
       81 
     | 
    
         
            -
                    reject(error);
         
     | 
| 
       82 
     | 
    
         
            -
                    this.onerror?.(error);
         
     | 
| 
       83 
     | 
    
         
            -
                  }
         
     | 
| 
       84 
     | 
    
         
            -
                });
         
     | 
| 
       85 
     | 
    
         
            -
              }
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
              private processReadBuffer() {
         
     | 
| 
       88 
     | 
    
         
            -
                while (true) {
         
     | 
| 
       89 
     | 
    
         
            -
                  try {
         
     | 
| 
       90 
     | 
    
         
            -
                    const message = this.readBuffer.readMessage();
         
     | 
| 
       91 
     | 
    
         
            -
                    if (message === null) {
         
     | 
| 
       92 
     | 
    
         
            -
                      break;
         
     | 
| 
       93 
     | 
    
         
            -
                    }
         
     | 
| 
       94 
     | 
    
         
            -
             
     | 
| 
       95 
     | 
    
         
            -
                    this.onmessage?.(message);
         
     | 
| 
       96 
     | 
    
         
            -
                  } catch (error) {
         
     | 
| 
       97 
     | 
    
         
            -
                    this.onerror?.(error as Error);
         
     | 
| 
       98 
     | 
    
         
            -
                  }
         
     | 
| 
       99 
     | 
    
         
            -
                }
         
     | 
| 
       100 
     | 
    
         
            -
              }
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
              async close(): Promise<void> {
         
     | 
| 
       103 
     | 
    
         
            -
                this.abortController.abort();
         
     | 
| 
       104 
     | 
    
         
            -
                this.process = undefined;
         
     | 
| 
       105 
     | 
    
         
            -
                this.readBuffer.clear();
         
     | 
| 
       106 
     | 
    
         
            -
              }
         
     | 
| 
       107 
     | 
    
         
            -
             
     | 
| 
       108 
     | 
    
         
            -
              send(message: JSONRPCMessage): Promise<void> {
         
     | 
| 
       109 
     | 
    
         
            -
                return new Promise(resolve => {
         
     | 
| 
       110 
     | 
    
         
            -
                  if (!this.process?.stdin) {
         
     | 
| 
       111 
     | 
    
         
            -
                    throw new MCPClientError({
         
     | 
| 
       112 
     | 
    
         
            -
                      message: 'StdioClientTransport not connected',
         
     | 
| 
       113 
     | 
    
         
            -
                    });
         
     | 
| 
       114 
     | 
    
         
            -
                  }
         
     | 
| 
       115 
     | 
    
         
            -
             
     | 
| 
       116 
     | 
    
         
            -
                  const json = serializeMessage(message);
         
     | 
| 
       117 
     | 
    
         
            -
                  if (this.process.stdin.write(json)) {
         
     | 
| 
       118 
     | 
    
         
            -
                    resolve();
         
     | 
| 
       119 
     | 
    
         
            -
                  } else {
         
     | 
| 
       120 
     | 
    
         
            -
                    this.process.stdin.once('drain', resolve);
         
     | 
| 
       121 
     | 
    
         
            -
                  }
         
     | 
| 
       122 
     | 
    
         
            -
                });
         
     | 
| 
       123 
     | 
    
         
            -
              }
         
     | 
| 
       124 
     | 
    
         
            -
            }
         
     | 
| 
       125 
     | 
    
         
            -
             
     | 
| 
       126 
     | 
    
         
            -
            class ReadBuffer {
         
     | 
| 
       127 
     | 
    
         
            -
              private buffer?: Buffer;
         
     | 
| 
       128 
     | 
    
         
            -
             
     | 
| 
       129 
     | 
    
         
            -
              append(chunk: Buffer): void {
         
     | 
| 
       130 
     | 
    
         
            -
                this.buffer = this.buffer ? Buffer.concat([this.buffer, chunk]) : chunk;
         
     | 
| 
       131 
     | 
    
         
            -
              }
         
     | 
| 
       132 
     | 
    
         
            -
             
     | 
| 
       133 
     | 
    
         
            -
              readMessage(): JSONRPCMessage | null {
         
     | 
| 
       134 
     | 
    
         
            -
                if (!this.buffer) return null;
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
                const index = this.buffer.indexOf('\n');
         
     | 
| 
       137 
     | 
    
         
            -
                if (index === -1) {
         
     | 
| 
       138 
     | 
    
         
            -
                  return null;
         
     | 
| 
       139 
     | 
    
         
            -
                }
         
     | 
| 
       140 
     | 
    
         
            -
             
     | 
| 
       141 
     | 
    
         
            -
                const line = this.buffer.toString('utf8', 0, index);
         
     | 
| 
       142 
     | 
    
         
            -
                this.buffer = this.buffer.subarray(index + 1);
         
     | 
| 
       143 
     | 
    
         
            -
                return deserializeMessage(line);
         
     | 
| 
       144 
     | 
    
         
            -
              }
         
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
              clear(): void {
         
     | 
| 
       147 
     | 
    
         
            -
                this.buffer = undefined;
         
     | 
| 
       148 
     | 
    
         
            -
              }
         
     | 
| 
       149 
     | 
    
         
            -
            }
         
     | 
| 
       150 
     | 
    
         
            -
             
     | 
| 
       151 
     | 
    
         
            -
            function serializeMessage(message: JSONRPCMessage): string {
         
     | 
| 
       152 
     | 
    
         
            -
              return JSON.stringify(message) + '\n';
         
     | 
| 
       153 
     | 
    
         
            -
            }
         
     | 
| 
       154 
     | 
    
         
            -
             
     | 
| 
       155 
     | 
    
         
            -
            export function deserializeMessage(line: string): JSONRPCMessage {
         
     | 
| 
       156 
     | 
    
         
            -
              return JSONRPCMessageSchema.parse(JSON.parse(line));
         
     | 
| 
       157 
     | 
    
         
            -
            }
         
     | 
    
        package/test/dist/index.js.map
    DELETED
    
    | 
         @@ -1 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            {"version":3,"sources":["../index.ts","../../core/test/not-implemented.ts","../../core/test/mock-embedding-model-v1.ts","../../core/test/mock-language-model-v1.ts","../../core/test/mock-values.ts","../../core/util/simulate-readable-stream.ts"],"sourcesContent":["export {\n  convertArrayToReadableStream,\n  mockId,\n} from '@ai-sdk/provider-utils/test';\nexport { MockEmbeddingModelV1 } from '../core/test/mock-embedding-model-v1';\nexport { MockLanguageModelV2 } from '../core/test/mock-language-model-v1';\nexport { mockValues } from '../core/test/mock-values';\n\nimport { simulateReadableStream as originalSimulateReadableStream } from '../core/util/simulate-readable-stream';\n\n/**\n * @deprecated Use `simulateReadableStream` from `ai` instead.\n */\nexport const simulateReadableStream = originalSimulateReadableStream;\n","export function notImplemented(): never {\n  throw new Error('Not implemented');\n}\n","import { EmbeddingModelV1 } from '@ai-sdk/provider';\nimport { Embedding } from '../types';\nimport { EmbeddingModelUsage } from '../types/usage';\nimport { notImplemented } from './not-implemented';\n\nexport class MockEmbeddingModelV1<VALUE> implements EmbeddingModelV1<VALUE> {\n  readonly specificationVersion = 'v1';\n\n  readonly provider: EmbeddingModelV1<VALUE>['provider'];\n  readonly modelId: EmbeddingModelV1<VALUE>['modelId'];\n  readonly maxEmbeddingsPerCall: EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall'];\n  readonly supportsParallelCalls: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n\n  doEmbed: EmbeddingModelV1<VALUE>['doEmbed'];\n\n  constructor({\n    provider = 'mock-provider',\n    modelId = 'mock-model-id',\n    maxEmbeddingsPerCall = 1,\n    supportsParallelCalls = false,\n    doEmbed = notImplemented,\n  }: {\n    provider?: EmbeddingModelV1<VALUE>['provider'];\n    modelId?: EmbeddingModelV1<VALUE>['modelId'];\n    maxEmbeddingsPerCall?:\n      | EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall']\n      | null;\n    supportsParallelCalls?: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n    doEmbed?: EmbeddingModelV1<VALUE>['doEmbed'];\n  } = {}) {\n    this.provider = provider;\n    this.modelId = modelId;\n    this.maxEmbeddingsPerCall = maxEmbeddingsPerCall ?? undefined;\n    this.supportsParallelCalls = supportsParallelCalls;\n    this.doEmbed = doEmbed;\n  }\n}\n\nexport function mockEmbed<VALUE>(\n  expectedValues: Array<VALUE>,\n  embeddings: Array<Embedding>,\n  usage?: EmbeddingModelUsage,\n): EmbeddingModelV1<VALUE>['doEmbed'] {\n  return async ({ values }) => {\n    assert.deepStrictEqual(expectedValues, values);\n    return { embeddings, usage };\n  };\n}\n","import { LanguageModelV2 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockLanguageModelV2 implements LanguageModelV2 {\n  readonly specificationVersion = 'v2';\n\n  readonly provider: LanguageModelV2['provider'];\n  readonly modelId: LanguageModelV2['modelId'];\n\n  supportsUrl: LanguageModelV2['supportsUrl'];\n  doGenerate: LanguageModelV2['doGenerate'];\n  doStream: LanguageModelV2['doStream'];\n\n  readonly defaultObjectGenerationMode: LanguageModelV2['defaultObjectGenerationMode'];\n  readonly supportsStructuredOutputs: LanguageModelV2['supportsStructuredOutputs'];\n  constructor({\n    provider = 'mock-provider',\n    modelId = 'mock-model-id',\n    supportsUrl = undefined,\n    doGenerate = notImplemented,\n    doStream = notImplemented,\n    defaultObjectGenerationMode = undefined,\n    supportsStructuredOutputs = undefined,\n  }: {\n    provider?: LanguageModelV2['provider'];\n    modelId?: LanguageModelV2['modelId'];\n    supportsUrl?: LanguageModelV2['supportsUrl'];\n    doGenerate?: LanguageModelV2['doGenerate'];\n    doStream?: LanguageModelV2['doStream'];\n    defaultObjectGenerationMode?: LanguageModelV2['defaultObjectGenerationMode'];\n    supportsStructuredOutputs?: LanguageModelV2['supportsStructuredOutputs'];\n  } = {}) {\n    this.provider = provider;\n    this.modelId = modelId;\n    this.doGenerate = doGenerate;\n    this.doStream = doStream;\n    this.supportsUrl = supportsUrl;\n\n    this.defaultObjectGenerationMode = defaultObjectGenerationMode;\n    this.supportsStructuredOutputs = supportsStructuredOutputs;\n  }\n}\n","export function mockValues<T>(...values: T[]): () => T {\n  let counter = 0;\n  return () => values[counter++] ?? values[values.length - 1];\n}\n","import { delay as delayFunction } from '@ai-sdk/provider-utils';\n\n/**\n * Creates a ReadableStream that emits the provided values with an optional delay between each value.\n *\n * @param options - The configuration options\n * @param options.chunks - Array of values to be emitted by the stream\n * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.\n * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.\n * @returns A ReadableStream that emits the provided values\n */\nexport function simulateReadableStream<T>({\n  chunks,\n  initialDelayInMs = 0,\n  chunkDelayInMs = 0,\n  _internal,\n}: {\n  chunks: T[];\n  initialDelayInMs?: number | null;\n  chunkDelayInMs?: number | null;\n  _internal?: {\n    delay?: (ms: number | null) => Promise<void>;\n  };\n}): ReadableStream<T> {\n  const delay = _internal?.delay ?? delayFunction;\n\n  let index = 0;\n\n  return new ReadableStream({\n    async pull(controller) {\n      if (index < chunks.length) {\n        await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);\n        controller.enqueue(chunks[index++]);\n      } else {\n        controller.close();\n      }\n    },\n  });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAAAA;AAAA;AAAA;AAAA,kBAGO;;;ACHA,SAAS,iBAAwB;AACtC,QAAM,IAAI,MAAM,iBAAiB;AACnC;;;ACGO,IAAM,uBAAN,MAAqE;AAAA,EAU1E,YAAY;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,uBAAuB;AAAA,IACvB,wBAAwB;AAAA,IACxB,UAAU;AAAA,EACZ,IAQI,CAAC,GAAG;AAvBR,SAAS,uBAAuB;AAwB9B,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,uBAAuB,sDAAwB;AACpD,SAAK,wBAAwB;AAC7B,SAAK,UAAU;AAAA,EACjB;AACF;;;ACjCO,IAAM,sBAAN,MAAqD;AAAA,EAY1D,YAAY;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,cAAc;AAAA,IACd,aAAa;AAAA,IACb,WAAW;AAAA,IACX,8BAA8B;AAAA,IAC9B,4BAA4B;AAAA,EAC9B,IAQI,CAAC,GAAG;AA3BR,SAAS,uBAAuB;AA4B9B,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,cAAc;AAEnB,SAAK,8BAA8B;AACnC,SAAK,4BAA4B;AAAA,EACnC;AACF;;;ACzCO,SAAS,cAAiB,QAAsB;AACrD,MAAI,UAAU;AACd,SAAO,MAAG;AAFZ;AAEe,wBAAO,SAAS,MAAhB,YAAqB,OAAO,OAAO,SAAS,CAAC;AAAA;AAC5D;;;ACHA,4BAAuC;AAWhC,SAAS,uBAA0B;AAAA,EACxC;AAAA,EACA,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB;AACF,GAOsB;AAvBtB;AAwBE,QAAM,SAAQ,4CAAW,UAAX,YAAoB,sBAAAC;AAElC,MAAI,QAAQ;AAEZ,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,KAAK,YAAY;AACrB,UAAI,QAAQ,OAAO,QAAQ;AACzB,cAAM,MAAM,UAAU,IAAI,mBAAmB,cAAc;AAC3D,mBAAW,QAAQ,OAAO,OAAO,CAAC;AAAA,MACpC,OAAO;AACL,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ALzBO,IAAMC,0BAAyB;","names":["simulateReadableStream","delayFunction","simulateReadableStream"]}
         
     | 
    
        package/test/dist/index.mjs.map
    DELETED
    
    | 
         @@ -1 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            {"version":3,"sources":["../index.ts","../../core/test/not-implemented.ts","../../core/test/mock-embedding-model-v1.ts","../../core/test/mock-language-model-v1.ts","../../core/test/mock-values.ts","../../core/util/simulate-readable-stream.ts"],"sourcesContent":["export {\n  convertArrayToReadableStream,\n  mockId,\n} from '@ai-sdk/provider-utils/test';\nexport { MockEmbeddingModelV1 } from '../core/test/mock-embedding-model-v1';\nexport { MockLanguageModelV2 } from '../core/test/mock-language-model-v1';\nexport { mockValues } from '../core/test/mock-values';\n\nimport { simulateReadableStream as originalSimulateReadableStream } from '../core/util/simulate-readable-stream';\n\n/**\n * @deprecated Use `simulateReadableStream` from `ai` instead.\n */\nexport const simulateReadableStream = originalSimulateReadableStream;\n","export function notImplemented(): never {\n  throw new Error('Not implemented');\n}\n","import { EmbeddingModelV1 } from '@ai-sdk/provider';\nimport { Embedding } from '../types';\nimport { EmbeddingModelUsage } from '../types/usage';\nimport { notImplemented } from './not-implemented';\n\nexport class MockEmbeddingModelV1<VALUE> implements EmbeddingModelV1<VALUE> {\n  readonly specificationVersion = 'v1';\n\n  readonly provider: EmbeddingModelV1<VALUE>['provider'];\n  readonly modelId: EmbeddingModelV1<VALUE>['modelId'];\n  readonly maxEmbeddingsPerCall: EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall'];\n  readonly supportsParallelCalls: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n\n  doEmbed: EmbeddingModelV1<VALUE>['doEmbed'];\n\n  constructor({\n    provider = 'mock-provider',\n    modelId = 'mock-model-id',\n    maxEmbeddingsPerCall = 1,\n    supportsParallelCalls = false,\n    doEmbed = notImplemented,\n  }: {\n    provider?: EmbeddingModelV1<VALUE>['provider'];\n    modelId?: EmbeddingModelV1<VALUE>['modelId'];\n    maxEmbeddingsPerCall?:\n      | EmbeddingModelV1<VALUE>['maxEmbeddingsPerCall']\n      | null;\n    supportsParallelCalls?: EmbeddingModelV1<VALUE>['supportsParallelCalls'];\n    doEmbed?: EmbeddingModelV1<VALUE>['doEmbed'];\n  } = {}) {\n    this.provider = provider;\n    this.modelId = modelId;\n    this.maxEmbeddingsPerCall = maxEmbeddingsPerCall ?? undefined;\n    this.supportsParallelCalls = supportsParallelCalls;\n    this.doEmbed = doEmbed;\n  }\n}\n\nexport function mockEmbed<VALUE>(\n  expectedValues: Array<VALUE>,\n  embeddings: Array<Embedding>,\n  usage?: EmbeddingModelUsage,\n): EmbeddingModelV1<VALUE>['doEmbed'] {\n  return async ({ values }) => {\n    assert.deepStrictEqual(expectedValues, values);\n    return { embeddings, usage };\n  };\n}\n","import { LanguageModelV2 } from '@ai-sdk/provider';\nimport { notImplemented } from './not-implemented';\n\nexport class MockLanguageModelV2 implements LanguageModelV2 {\n  readonly specificationVersion = 'v2';\n\n  readonly provider: LanguageModelV2['provider'];\n  readonly modelId: LanguageModelV2['modelId'];\n\n  supportsUrl: LanguageModelV2['supportsUrl'];\n  doGenerate: LanguageModelV2['doGenerate'];\n  doStream: LanguageModelV2['doStream'];\n\n  readonly defaultObjectGenerationMode: LanguageModelV2['defaultObjectGenerationMode'];\n  readonly supportsStructuredOutputs: LanguageModelV2['supportsStructuredOutputs'];\n  constructor({\n    provider = 'mock-provider',\n    modelId = 'mock-model-id',\n    supportsUrl = undefined,\n    doGenerate = notImplemented,\n    doStream = notImplemented,\n    defaultObjectGenerationMode = undefined,\n    supportsStructuredOutputs = undefined,\n  }: {\n    provider?: LanguageModelV2['provider'];\n    modelId?: LanguageModelV2['modelId'];\n    supportsUrl?: LanguageModelV2['supportsUrl'];\n    doGenerate?: LanguageModelV2['doGenerate'];\n    doStream?: LanguageModelV2['doStream'];\n    defaultObjectGenerationMode?: LanguageModelV2['defaultObjectGenerationMode'];\n    supportsStructuredOutputs?: LanguageModelV2['supportsStructuredOutputs'];\n  } = {}) {\n    this.provider = provider;\n    this.modelId = modelId;\n    this.doGenerate = doGenerate;\n    this.doStream = doStream;\n    this.supportsUrl = supportsUrl;\n\n    this.defaultObjectGenerationMode = defaultObjectGenerationMode;\n    this.supportsStructuredOutputs = supportsStructuredOutputs;\n  }\n}\n","export function mockValues<T>(...values: T[]): () => T {\n  let counter = 0;\n  return () => values[counter++] ?? values[values.length - 1];\n}\n","import { delay as delayFunction } from '@ai-sdk/provider-utils';\n\n/**\n * Creates a ReadableStream that emits the provided values with an optional delay between each value.\n *\n * @param options - The configuration options\n * @param options.chunks - Array of values to be emitted by the stream\n * @param options.initialDelayInMs - Optional initial delay in milliseconds before emitting the first value (default: 0). Can be set to `null` to skip the initial delay. The difference between `initialDelayInMs: null` and `initialDelayInMs: 0` is that `initialDelayInMs: null` will emit the values without any delay, while `initialDelayInMs: 0` will emit the values with a delay of 0 milliseconds.\n * @param options.chunkDelayInMs - Optional delay in milliseconds between emitting each value (default: 0). Can be set to `null` to skip the delay. The difference between `chunkDelayInMs: null` and `chunkDelayInMs: 0` is that `chunkDelayInMs: null` will emit the values without any delay, while `chunkDelayInMs: 0` will emit the values with a delay of 0 milliseconds.\n * @returns A ReadableStream that emits the provided values\n */\nexport function simulateReadableStream<T>({\n  chunks,\n  initialDelayInMs = 0,\n  chunkDelayInMs = 0,\n  _internal,\n}: {\n  chunks: T[];\n  initialDelayInMs?: number | null;\n  chunkDelayInMs?: number | null;\n  _internal?: {\n    delay?: (ms: number | null) => Promise<void>;\n  };\n}): ReadableStream<T> {\n  const delay = _internal?.delay ?? delayFunction;\n\n  let index = 0;\n\n  return new ReadableStream({\n    async pull(controller) {\n      if (index < chunks.length) {\n        await delay(index === 0 ? initialDelayInMs : chunkDelayInMs);\n        controller.enqueue(chunks[index++]);\n      } else {\n        controller.close();\n      }\n    },\n  });\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;;;ACHA,SAAS,iBAAwB;AACtC,QAAM,IAAI,MAAM,iBAAiB;AACnC;;;ACGO,IAAM,uBAAN,MAAqE;AAAA,EAU1E,YAAY;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,uBAAuB;AAAA,IACvB,wBAAwB;AAAA,IACxB,UAAU;AAAA,EACZ,IAQI,CAAC,GAAG;AAvBR,SAAS,uBAAuB;AAwB9B,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,uBAAuB,sDAAwB;AACpD,SAAK,wBAAwB;AAC7B,SAAK,UAAU;AAAA,EACjB;AACF;;;ACjCO,IAAM,sBAAN,MAAqD;AAAA,EAY1D,YAAY;AAAA,IACV,WAAW;AAAA,IACX,UAAU;AAAA,IACV,cAAc;AAAA,IACd,aAAa;AAAA,IACb,WAAW;AAAA,IACX,8BAA8B;AAAA,IAC9B,4BAA4B;AAAA,EAC9B,IAQI,CAAC,GAAG;AA3BR,SAAS,uBAAuB;AA4B9B,SAAK,WAAW;AAChB,SAAK,UAAU;AACf,SAAK,aAAa;AAClB,SAAK,WAAW;AAChB,SAAK,cAAc;AAEnB,SAAK,8BAA8B;AACnC,SAAK,4BAA4B;AAAA,EACnC;AACF;;;ACzCO,SAAS,cAAiB,QAAsB;AACrD,MAAI,UAAU;AACd,SAAO,MAAG;AAFZ;AAEe,wBAAO,SAAS,MAAhB,YAAqB,OAAO,OAAO,SAAS,CAAC;AAAA;AAC5D;;;ACHA,SAAS,SAAS,qBAAqB;AAWhC,SAAS,uBAA0B;AAAA,EACxC;AAAA,EACA,mBAAmB;AAAA,EACnB,iBAAiB;AAAA,EACjB;AACF,GAOsB;AAvBtB;AAwBE,QAAM,SAAQ,4CAAW,UAAX,YAAoB;AAElC,MAAI,QAAQ;AAEZ,SAAO,IAAI,eAAe;AAAA,IACxB,MAAM,KAAK,YAAY;AACrB,UAAI,QAAQ,OAAO,QAAQ;AACzB,cAAM,MAAM,UAAU,IAAI,mBAAmB,cAAc;AAC3D,mBAAW,QAAQ,OAAO,OAAO,CAAC;AAAA,MACpC,OAAO;AACL,mBAAW,MAAM;AAAA,MACnB;AAAA,IACF;AAAA,EACF,CAAC;AACH;;;ALzBO,IAAMA,0BAAyB;","names":["simulateReadableStream"]}
         
     | 
| 
         @@ -15,16 +15,16 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS 
     | 
|
| 
       15 
15 
     | 
    
         
             
                    _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
         
     | 
| 
       16 
16 
     | 
    
         
             
                }, z.ZodTypeAny, "passthrough">>>;
         
     | 
| 
       17 
17 
     | 
    
         
             
            }>, "strict", z.ZodTypeAny, {
         
     | 
| 
      
 18 
     | 
    
         
            +
                id: string | number;
         
     | 
| 
       18 
19 
     | 
    
         
             
                method: string;
         
     | 
| 
       19 
20 
     | 
    
         
             
                jsonrpc: "2.0";
         
     | 
| 
       20 
     | 
    
         
            -
                id: string | number;
         
     | 
| 
       21 
21 
     | 
    
         
             
                params?: z.objectOutputType<{
         
     | 
| 
       22 
22 
     | 
    
         
             
                    _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
         
     | 
| 
       23 
23 
     | 
    
         
             
                }, z.ZodTypeAny, "passthrough"> | undefined;
         
     | 
| 
       24 
24 
     | 
    
         
             
            }, {
         
     | 
| 
      
 25 
     | 
    
         
            +
                id: string | number;
         
     | 
| 
       25 
26 
     | 
    
         
             
                method: string;
         
     | 
| 
       26 
27 
     | 
    
         
             
                jsonrpc: "2.0";
         
     | 
| 
       27 
     | 
    
         
            -
                id: string | number;
         
     | 
| 
       28 
28 
     | 
    
         
             
                params?: z.objectInputType<{
         
     | 
| 
       29 
29 
     | 
    
         
             
                    _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
         
     | 
| 
       30 
30 
     | 
    
         
             
                }, z.ZodTypeAny, "passthrough"> | undefined;
         
     | 
| 
         @@ -67,16 +67,16 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS 
     | 
|
| 
       67 
67 
     | 
    
         
             
                } & {
         
     | 
| 
       68 
68 
     | 
    
         
             
                    [k: string]: unknown;
         
     | 
| 
       69 
69 
     | 
    
         
             
                };
         
     | 
| 
       70 
     | 
    
         
            -
                jsonrpc: "2.0";
         
     | 
| 
       71 
70 
     | 
    
         
             
                id: string | number;
         
     | 
| 
      
 71 
     | 
    
         
            +
                jsonrpc: "2.0";
         
     | 
| 
       72 
72 
     | 
    
         
             
            }, {
         
     | 
| 
       73 
73 
     | 
    
         
             
                result: {
         
     | 
| 
       74 
74 
     | 
    
         
             
                    _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
         
     | 
| 
       75 
75 
     | 
    
         
             
                } & {
         
     | 
| 
       76 
76 
     | 
    
         
             
                    [k: string]: unknown;
         
     | 
| 
       77 
77 
     | 
    
         
             
                };
         
     | 
| 
       78 
     | 
    
         
            -
                jsonrpc: "2.0";
         
     | 
| 
       79 
78 
     | 
    
         
             
                id: string | number;
         
     | 
| 
      
 79 
     | 
    
         
            +
                jsonrpc: "2.0";
         
     | 
| 
       80 
80 
     | 
    
         
             
            }>, z.ZodObject<{
         
     | 
| 
       81 
81 
     | 
    
         
             
                jsonrpc: z.ZodLiteral<"2.0">;
         
     | 
| 
       82 
82 
     | 
    
         
             
                id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
         
     | 
| 
         @@ -99,16 +99,16 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS 
     | 
|
| 
       99 
99 
     | 
    
         
             
                    message: string;
         
     | 
| 
       100 
100 
     | 
    
         
             
                    data?: unknown;
         
     | 
| 
       101 
101 
     | 
    
         
             
                };
         
     | 
| 
       102 
     | 
    
         
            -
                jsonrpc: "2.0";
         
     | 
| 
       103 
102 
     | 
    
         
             
                id: string | number;
         
     | 
| 
      
 103 
     | 
    
         
            +
                jsonrpc: "2.0";
         
     | 
| 
       104 
104 
     | 
    
         
             
            }, {
         
     | 
| 
       105 
105 
     | 
    
         
             
                error: {
         
     | 
| 
       106 
106 
     | 
    
         
             
                    code: number;
         
     | 
| 
       107 
107 
     | 
    
         
             
                    message: string;
         
     | 
| 
       108 
108 
     | 
    
         
             
                    data?: unknown;
         
     | 
| 
       109 
109 
     | 
    
         
             
                };
         
     | 
| 
       110 
     | 
    
         
            -
                jsonrpc: "2.0";
         
     | 
| 
       111 
110 
     | 
    
         
             
                id: string | number;
         
     | 
| 
      
 111 
     | 
    
         
            +
                jsonrpc: "2.0";
         
     | 
| 
       112 
112 
     | 
    
         
             
            }>]>;
         
     | 
| 
       113 
113 
     | 
    
         
             
            type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
         @@ -15,16 +15,16 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS 
     | 
|
| 
       15 
15 
     | 
    
         
             
                    _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
         
     | 
| 
       16 
16 
     | 
    
         
             
                }, z.ZodTypeAny, "passthrough">>>;
         
     | 
| 
       17 
17 
     | 
    
         
             
            }>, "strict", z.ZodTypeAny, {
         
     | 
| 
      
 18 
     | 
    
         
            +
                id: string | number;
         
     | 
| 
       18 
19 
     | 
    
         
             
                method: string;
         
     | 
| 
       19 
20 
     | 
    
         
             
                jsonrpc: "2.0";
         
     | 
| 
       20 
     | 
    
         
            -
                id: string | number;
         
     | 
| 
       21 
21 
     | 
    
         
             
                params?: z.objectOutputType<{
         
     | 
| 
       22 
22 
     | 
    
         
             
                    _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
         
     | 
| 
       23 
23 
     | 
    
         
             
                }, z.ZodTypeAny, "passthrough"> | undefined;
         
     | 
| 
       24 
24 
     | 
    
         
             
            }, {
         
     | 
| 
      
 25 
     | 
    
         
            +
                id: string | number;
         
     | 
| 
       25 
26 
     | 
    
         
             
                method: string;
         
     | 
| 
       26 
27 
     | 
    
         
             
                jsonrpc: "2.0";
         
     | 
| 
       27 
     | 
    
         
            -
                id: string | number;
         
     | 
| 
       28 
28 
     | 
    
         
             
                params?: z.objectInputType<{
         
     | 
| 
       29 
29 
     | 
    
         
             
                    _meta: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
         
     | 
| 
       30 
30 
     | 
    
         
             
                }, z.ZodTypeAny, "passthrough"> | undefined;
         
     | 
| 
         @@ -67,16 +67,16 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS 
     | 
|
| 
       67 
67 
     | 
    
         
             
                } & {
         
     | 
| 
       68 
68 
     | 
    
         
             
                    [k: string]: unknown;
         
     | 
| 
       69 
69 
     | 
    
         
             
                };
         
     | 
| 
       70 
     | 
    
         
            -
                jsonrpc: "2.0";
         
     | 
| 
       71 
70 
     | 
    
         
             
                id: string | number;
         
     | 
| 
      
 71 
     | 
    
         
            +
                jsonrpc: "2.0";
         
     | 
| 
       72 
72 
     | 
    
         
             
            }, {
         
     | 
| 
       73 
73 
     | 
    
         
             
                result: {
         
     | 
| 
       74 
74 
     | 
    
         
             
                    _meta?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
         
     | 
| 
       75 
75 
     | 
    
         
             
                } & {
         
     | 
| 
       76 
76 
     | 
    
         
             
                    [k: string]: unknown;
         
     | 
| 
       77 
77 
     | 
    
         
             
                };
         
     | 
| 
       78 
     | 
    
         
            -
                jsonrpc: "2.0";
         
     | 
| 
       79 
78 
     | 
    
         
             
                id: string | number;
         
     | 
| 
      
 79 
     | 
    
         
            +
                jsonrpc: "2.0";
         
     | 
| 
       80 
80 
     | 
    
         
             
            }>, z.ZodObject<{
         
     | 
| 
       81 
81 
     | 
    
         
             
                jsonrpc: z.ZodLiteral<"2.0">;
         
     | 
| 
       82 
82 
     | 
    
         
             
                id: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
         
     | 
| 
         @@ -99,16 +99,16 @@ declare const JSONRPCMessageSchema: z.ZodUnion<[z.ZodObject<z.objectUtil.extendS 
     | 
|
| 
       99 
99 
     | 
    
         
             
                    message: string;
         
     | 
| 
       100 
100 
     | 
    
         
             
                    data?: unknown;
         
     | 
| 
       101 
101 
     | 
    
         
             
                };
         
     | 
| 
       102 
     | 
    
         
            -
                jsonrpc: "2.0";
         
     | 
| 
       103 
102 
     | 
    
         
             
                id: string | number;
         
     | 
| 
      
 103 
     | 
    
         
            +
                jsonrpc: "2.0";
         
     | 
| 
       104 
104 
     | 
    
         
             
            }, {
         
     | 
| 
       105 
105 
     | 
    
         
             
                error: {
         
     | 
| 
       106 
106 
     | 
    
         
             
                    code: number;
         
     | 
| 
       107 
107 
     | 
    
         
             
                    message: string;
         
     | 
| 
       108 
108 
     | 
    
         
             
                    data?: unknown;
         
     | 
| 
       109 
109 
     | 
    
         
             
                };
         
     | 
| 
       110 
     | 
    
         
            -
                jsonrpc: "2.0";
         
     | 
| 
       111 
110 
     | 
    
         
             
                id: string | number;
         
     | 
| 
      
 111 
     | 
    
         
            +
                jsonrpc: "2.0";
         
     | 
| 
       112 
112 
     | 
    
         
             
            }>]>;
         
     | 
| 
       113 
113 
     | 
    
         
             
            type JSONRPCMessage = z.infer<typeof JSONRPCMessageSchema>;
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     | 
| 
         
            File without changes
         
     |