import type { ConnectorCount, TrafficIncidentDetails } from "@tomtom-org/maps-sdk/core"; import { APP_DATA_META_KEY } from "../../constants"; import type { ResponseDetail } from "../../schemas/shared/responseOptions"; import { type WithAppData } from "./appData"; import { type GeometryFeature } from "./geometryResponse"; /** The incidents the SDK returns, with the summary the cap adds when it drops some. */ export type TrafficResponse = TrafficIncidentDetails & { incidentSummary?: TrafficIncidentSummary; }; export interface TrafficIncidentSummary { totalIncidents: number; returnedIncidents: number; truncated: true; incidentsByCategory: Record; note: string; } /** MCP response content structure */ export interface MCPResponseContent { type: "text"; text: string; } /** * `show_ui`, the tool the app reports, and the app data under `com.tomtom/app-data`. * The index signature is the MCP SDK's `_meta` shape, which allows any key. */ export interface ResponseMeta { show_ui?: boolean; tool?: string; [APP_DATA_META_KEY]?: string; [key: string]: unknown; } export interface MCPResponse extends WithAppData { content: MCPResponseContent[]; isError?: boolean; _meta?: ResponseMeta; [key: string]: unknown; } /** * Optional fields that compact drops unless the caller asked for them with the * matching tool parameter (openingHours, timeZone, mapcodes, * extendedPostalCodesFor, relatedPois, addressRanges, timeValidityFilter). */ export interface RequestedFields { openingHours?: boolean; timeZone?: boolean; mapcodes?: boolean; extendedPostalCode?: boolean; relatedPois?: boolean; addressRanges?: boolean; /** Traffic: per-incident timeValidity (timeValidityFilter other than "present"). */ timeValidity?: boolean; } /** Which optional search fields a tool call asked for, from its parameters. */ export declare function requestedSearchFields(params: { openingHours?: unknown; timeZone?: unknown; mapcodes?: unknown; extendedPostalCodesFor?: unknown; relatedPois?: unknown; addressRanges?: unknown; }): RequestedFields; /** Traffic: keep timeValidity when the filter asks for more than present incidents. */ export declare function requestedTrafficFields(timeValidityFilter?: string[]): RequestedFields; /** * Flatten the SDK's grouped connectors to the fields an agent reasons about. * Drops voltage and current, which follow from the rated power. */ export declare function flattenConnectors(connectors: ConnectorCount[]): Array>; /** * Trim verbose properties from an SDK place's properties object. * Field names follow the SDK's parsed shape, not the raw API: the SDK already * turns classifications into categories/localizedCategories, drops categorySet, * and moves viewport/boundingBox to feature.bbox (see trimSearchFeature). * * Removes: * - POI: localizedCategories (the category codes stay) * - Charging: chargingPark.chargingStations, per charging point (the connectors summarize them) * - Metadata: dataSources, matchConfidence, info, score, entryPoints * - Address: countryCodeISO3, countrySubdivisionCode(Iso), countrySubdivisionName, localName * - Unless requested: poi.openingHours, poi.timeZone, mapcodes, address.extendedPostalCode, * relatedPois, addressRanges * * Keeps: * - POI: name, phone, url, categories, brands * - Address: freeformAddress, streetName, streetNumber, municipality, postalCode, countryCode, country, countrySubdivision * - Core: type, distance, chargingPark (connectors flattened), geometry */ export declare function trimGeoJSONFeatureProperties(props: Record, requested?: RequestedFields): void; /** * Trim an SDK place feature: its properties, plus feature.bbox, which is * the SDK's home for the API's viewport/boundingBox (map display bounds). */ export declare function trimSearchFeature(feature: Record, requested?: RequestedFields): void; /** * Trim routing response - removes large coordinate arrays and guidance instructions. * * SDK format (GeoJSON FeatureCollection): * - features[].geometry.coordinates (full route polyline) * - features[].bbox, properties.guidance, properties.progress * - properties.sections: see trimRouteSections */ export declare function trimRoutingResponse(response: unknown): unknown; /** * Trim search response - removes verbose POI details and metadata. * * SDK format (GeoJSON FeatureCollection or single Feature): * - properties.queryTime, fuzzyLevel, geoBias, nextCursor (collection summary) * - features[]: see trimSearchFeature */ export declare function trimSearchResponse(response: unknown, requested?: RequestedFields): unknown; /** * Trim the traffic response to one flat object per incident. * * Drops the GeoJSON envelope (coordinates are for the map, which gets the full result), * the long internal `id`, `numberOfReports`, `lastReportTime` and * `probabilityOfOccurrence`, and repeats each event description once. * `timeValidity` is kept only when requested, i.e. the filter also asks for future incidents. */ export declare function trimTrafficResponse(response: TrafficResponse, requested?: RequestedFields): { incidents: Array>; incidentSummary?: TrafficIncidentSummary; }; /** Default maximum incidents returned to the agent (large bboxes can return thousands). */ export declare const DEFAULT_MAX_TRAFFIC_INCIDENTS = 100; /** * Cap the number of traffic incidents returned to the agent. * * Large bounding boxes can return thousands of incidents, overflowing client context limits. * Over the cap, the most severe incidents (by magnitudeOfDelay) are kept and an * `incidentSummary` records the full totals so the agent knows the response was truncated. */ export declare function capTrafficIncidents(response: TrafficIncidentDetails, maxIncidents?: number): TrafficResponse; /** * Build the MCP error response for a failed tool call, logging the formatted error. */ export declare function buildErrorResponse(error: unknown, context: string): MCPResponse; /** The MCP error response carrying the error's payload. */ export declare function errorResult(error: Error): MCPResponse; /** * Build the MCP response for a successful tool call. With response_detail "full" * the agent gets `full` untrimmed; otherwise it gets `trim(full)` and the app * gets `appData`, the full result unless given. With "geometry", `trim(full)` * also carries the features `geometry(full)` builds. */ export declare function buildToolResponse(full: T, trim: (full: T) => unknown, options: { showUI: boolean; responseDetail: ResponseDetail | undefined; /** What the app draws; null for an app that draws from its tool input alone. */ appData?: unknown; geometry?: (full: T) => Array; }): Promise; /** * Build the MCP response for a tool with an MCP App (CONTEXT.md, App data): * - `trimmedData` for the agent, as minified JSON text, since indentation costs tokens; * - one result `_meta`: `show_ui` and `appData` under `com.tomtom/app-data` when the * whole result fits (route lines simplified to fit unless `exact`). A null `appData` * gives the app nothing. The server also keeps the app data beside the result under APP_DATA. */ export declare function buildCompressedResponse(trimmedData: T, appData: unknown, { showUI, exact }?: { showUI?: boolean; exact?: boolean; }): Promise; //# sourceMappingURL=responseTrimmer.d.ts.map