( rawParams: Record<string, unknown>, context: ExecutionContext )
| 111 | } |
| 112 | |
| 113 | export async function executeOpenResource( |
| 114 | rawParams: Record<string, unknown>, |
| 115 | context: ExecutionContext |
| 116 | ): Promise<ToolCallResult> { |
| 117 | const params = rawParams as OpenResourceParams |
| 118 | |
| 119 | const items: OpenResourceItem[] = |
| 120 | params.resources ?? |
| 121 | (params.type && (params.id || params.path) |
| 122 | ? [{ type: params.type, id: params.id, path: params.path }] |
| 123 | : []) |
| 124 | |
| 125 | if (items.length === 0) { |
| 126 | return { success: false, error: 'resources array is required' } |
| 127 | } |
| 128 | |
| 129 | const resources: MothershipResource[] = [] |
| 130 | const errors: string[] = [] |
| 131 | |
| 132 | for (const item of items) { |
| 133 | const validated = validateOpenResourceItem(item) |
| 134 | if (!validated.success) { |
| 135 | errors.push(validated.error) |
| 136 | continue |
| 137 | } |
| 138 | const result = await resolveResource(validated.params, context) |
| 139 | if ('error' in result) { |
| 140 | errors.push(result.error) |
| 141 | } else { |
| 142 | resources.push(result) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | return { |
| 147 | success: resources.length > 0, |
| 148 | output: { opened: resources.length, errors }, |
| 149 | resources, |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | function validateOpenResourceItem( |
| 154 | item: OpenResourceItem |
no test coverage detected