-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathRetrieveStyleTool.ts
More file actions
37 lines (31 loc) · 1.11 KB
/
RetrieveStyleTool.ts
File metadata and controls
37 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { filterExpandedMapboxStyles } from '../../utils/styleUtils.js';
import { MapboxApiBasedTool } from '../MapboxApiBasedTool.js';
import {
RetrieveStyleSchema,
RetrieveStyleInput
} from './RetrieveStyleTool.schema.js';
export class RetrieveStyleTool extends MapboxApiBasedTool<
typeof RetrieveStyleSchema
> {
name = 'retrieve_style_tool';
description = 'Retrieve a specific Mapbox style by ID';
constructor() {
super({ inputSchema: RetrieveStyleSchema });
}
protected async execute(
input: RetrieveStyleInput,
accessToken?: string
): Promise<any> {
const username = MapboxApiBasedTool.getUserNameFromToken(accessToken);
const url = `${MapboxApiBasedTool.mapboxApiEndpoint}styles/v1/${username}/${input.styleId}?access_token=${accessToken}`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(
`Failed to retrieve style: ${response.status} ${response.statusText}`
);
}
const data = await response.json();
// Always filter out expanded Mapbox styles to prevent token overflow
return filterExpandedMapboxStyles(data);
}
}