(
config: AimockConfig,
overrides?: { port?: number; host?: string },
)
| 110 | } |
| 111 | |
| 112 | export async function startFromConfig( |
| 113 | config: AimockConfig, |
| 114 | overrides?: { port?: number; host?: string }, |
| 115 | ): Promise<{ llmock: LLMock; url: string }> { |
| 116 | const logger = new Logger("info"); |
| 117 | |
| 118 | // Load fixtures if specified |
| 119 | const llmock = new LLMock({ |
| 120 | port: overrides?.port ?? config.port ?? 0, |
| 121 | host: overrides?.host ?? config.host ?? "127.0.0.1", |
| 122 | chaos: config.llm?.chaos, |
| 123 | record: config.llm?.record, |
| 124 | metrics: config.metrics, |
| 125 | strict: config.strict, |
| 126 | }); |
| 127 | |
| 128 | if (config.llm?.fixtures) { |
| 129 | const fixturePath = path.resolve(config.llm.fixtures); |
| 130 | const stat = fs.statSync(fixturePath); |
| 131 | if (stat.isDirectory()) { |
| 132 | llmock.loadFixtureDir(fixturePath); |
| 133 | } else { |
| 134 | llmock.loadFixtureFile(fixturePath); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | // MCP |
| 139 | if (config.mcp) { |
| 140 | const mcpConfig = config.mcp; |
| 141 | const mcp = new MCPMock({ |
| 142 | serverInfo: mcpConfig.serverInfo, |
| 143 | }); |
| 144 | |
| 145 | if (mcpConfig.tools) { |
| 146 | for (const tool of mcpConfig.tools) { |
| 147 | const { result, ...def } = tool; |
| 148 | mcp.addTool(def); |
| 149 | if (result !== undefined) { |
| 150 | mcp.onToolCall(def.name, () => result); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | if (mcpConfig.resources) { |
| 156 | for (const res of mcpConfig.resources) { |
| 157 | mcp.addResource( |
| 158 | { uri: res.uri, name: res.name, mimeType: res.mimeType, description: res.description }, |
| 159 | res.text !== undefined || res.blob !== undefined |
| 160 | ? { text: res.text, blob: res.blob, mimeType: res.mimeType } |
| 161 | : undefined, |
| 162 | ); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if (mcpConfig.prompts) { |
| 167 | for (const prompt of mcpConfig.prompts) { |
| 168 | const { result, ...def } = prompt; |
| 169 | if (result) { |
no test coverage detected
searching dependent graphs…