( executor: CommandExecutor = getDefaultCommandExecutor(), )
| 14 | import { renderTranscript } from '../../rendering/render.ts'; |
| 15 | |
| 16 | export async function devicesResourceLogic( |
| 17 | executor: CommandExecutor = getDefaultCommandExecutor(), |
| 18 | ): Promise<{ contents: Array<{ text: string }> }> { |
| 19 | const ctx: ToolHandlerContext = { |
| 20 | emit: () => {}, |
| 21 | attach: () => {}, |
| 22 | }; |
| 23 | |
| 24 | try { |
| 25 | log('info', 'Processing devices resource request'); |
| 26 | await handlerContextStorage.run(ctx, () => list_devicesLogic({}, executor)); |
| 27 | const text = renderTranscript( |
| 28 | { |
| 29 | structuredOutput: ctx.structuredOutput, |
| 30 | nextSteps: ctx.nextSteps, |
| 31 | nextStepsRuntime: 'mcp', |
| 32 | }, |
| 33 | 'text', |
| 34 | { runtime: 'mcp' }, |
| 35 | ); |
| 36 | const isError = ctx.structuredOutput?.result.didError === true; |
| 37 | if (isError) { |
| 38 | throw new Error(text || 'Failed to retrieve device data'); |
| 39 | } |
| 40 | return { |
| 41 | contents: [ |
| 42 | { |
| 43 | text: text || 'No device data available', |
| 44 | }, |
| 45 | ], |
| 46 | }; |
| 47 | } catch (error) { |
| 48 | const errorMessage = error instanceof Error ? error.message : String(error); |
| 49 | log('error', `Error in devices resource handler: ${errorMessage}`); |
| 50 | |
| 51 | return { |
| 52 | contents: [ |
| 53 | { |
| 54 | text: `Error retrieving device data: ${errorMessage}`, |
| 55 | }, |
| 56 | ], |
| 57 | }; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | export async function handler(_uri: URL): Promise<{ contents: Array<{ text: string }> }> { |
| 62 | return devicesResourceLogic(); |
no test coverage detected