imprint-mcp 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/README.md +6 -4
  2. package/examples/discoverandgo/README.md +1 -1
  3. package/examples/discoverandgo/book_discoverandgo_museum_pass/workflow.json +7 -0
  4. package/examples/google-flights/README.md +41 -14
  5. package/examples/google-flights/_shared/google_batchexecute_parser.ts +165 -0
  6. package/examples/google-flights/_shared/google_flights_transport.ts +70 -0
  7. package/examples/google-flights/_shared/google_flights_types.ts +56 -0
  8. package/examples/google-flights/get_flight_booking_options/backends.json +43 -0
  9. package/examples/google-flights/get_flight_booking_options/index.ts +129 -0
  10. package/examples/google-flights/get_flight_booking_options/parser.ts +209 -0
  11. package/examples/google-flights/get_flight_booking_options/playbook.yaml +46 -0
  12. package/examples/google-flights/get_flight_booking_options/request-transform.ts +210 -0
  13. package/examples/google-flights/get_flight_booking_options/workflow.json +85 -0
  14. package/examples/google-flights/get_flight_calendar_prices/backends.json +27 -0
  15. package/examples/google-flights/get_flight_calendar_prices/index.ts +44 -29
  16. package/examples/google-flights/get_flight_calendar_prices/parser.ts +76 -69
  17. package/examples/google-flights/get_flight_calendar_prices/playbook.yaml +67 -40
  18. package/examples/google-flights/get_flight_calendar_prices/workflow.json +29 -17
  19. package/examples/google-flights/get_flight_location_details/backends.json +27 -0
  20. package/examples/google-flights/{lookup_airport → get_flight_location_details}/index.ts +30 -20
  21. package/examples/google-flights/get_flight_location_details/parser.ts +103 -0
  22. package/examples/google-flights/get_flight_location_details/playbook.yaml +59 -0
  23. package/examples/google-flights/{lookup_airport → get_flight_location_details}/workflow.json +19 -12
  24. package/examples/google-flights/lookup_flight_locations/backends.json +27 -0
  25. package/examples/google-flights/lookup_flight_locations/index.ts +111 -0
  26. package/examples/google-flights/lookup_flight_locations/package.json +9 -0
  27. package/examples/google-flights/lookup_flight_locations/parser.ts +135 -0
  28. package/examples/google-flights/lookup_flight_locations/playbook.yaml +47 -0
  29. package/examples/google-flights/lookup_flight_locations/request-transform.ts +53 -0
  30. package/examples/google-flights/lookup_flight_locations/workflow.json +64 -0
  31. package/examples/google-flights/search_flights/backends.json +42 -0
  32. package/examples/google-flights/search_flights/index.ts +105 -69
  33. package/examples/google-flights/search_flights/parser.ts +186 -183
  34. package/examples/google-flights/search_flights/playbook.yaml +295 -88
  35. package/examples/google-flights/search_flights/request-transform.ts +247 -92
  36. package/examples/google-flights/search_flights/workflow.json +66 -40
  37. package/examples/google-flights/validate_flight_itinerary/backends.json +27 -0
  38. package/examples/google-flights/validate_flight_itinerary/index.ts +103 -0
  39. package/examples/google-flights/validate_flight_itinerary/package.json +9 -0
  40. package/examples/google-flights/validate_flight_itinerary/parser.ts +101 -0
  41. package/examples/google-flights/validate_flight_itinerary/playbook.yaml +84 -0
  42. package/examples/google-flights/validate_flight_itinerary/request-transform.ts +92 -0
  43. package/examples/google-flights/validate_flight_itinerary/workflow.json +59 -0
  44. package/examples/google-hotels/README.md +40 -15
  45. package/examples/google-hotels/get_hotel_details/backends.json +16 -0
  46. package/examples/google-hotels/get_hotel_details/index.ts +122 -0
  47. package/examples/google-hotels/get_hotel_details/parser.ts +275 -0
  48. package/examples/google-hotels/get_hotel_details/playbook.yaml +40 -0
  49. package/examples/google-hotels/get_hotel_details/request-transform.ts +67 -0
  50. package/examples/google-hotels/get_hotel_details/workflow.json +67 -0
  51. package/examples/google-hotels/get_hotel_photos/backends.json +16 -0
  52. package/examples/google-hotels/get_hotel_photos/index.ts +90 -0
  53. package/examples/google-hotels/get_hotel_photos/parser.ts +75 -0
  54. package/examples/google-hotels/get_hotel_photos/playbook.yaml +23 -0
  55. package/examples/google-hotels/get_hotel_photos/request-transform.ts +27 -0
  56. package/examples/google-hotels/get_hotel_photos/workflow.json +44 -0
  57. package/examples/google-hotels/get_hotel_reviews/backends.json +16 -0
  58. package/examples/google-hotels/get_hotel_reviews/index.ts +14 -17
  59. package/examples/google-hotels/get_hotel_reviews/parser.ts +177 -105
  60. package/examples/google-hotels/get_hotel_reviews/playbook.yaml +9 -54
  61. package/examples/google-hotels/get_hotel_reviews/workflow.json +10 -13
  62. package/examples/google-hotels/get_travel_area_boundaries/backends.json +16 -0
  63. package/examples/google-hotels/get_travel_area_boundaries/index.ts +104 -0
  64. package/examples/google-hotels/get_travel_area_boundaries/package.json +9 -0
  65. package/examples/google-hotels/get_travel_area_boundaries/parser.ts +127 -0
  66. package/examples/google-hotels/get_travel_area_boundaries/playbook.yaml +38 -0
  67. package/examples/google-hotels/get_travel_area_boundaries/request-transform.ts +52 -0
  68. package/examples/google-hotels/get_travel_area_boundaries/workflow.json +54 -0
  69. package/examples/google-hotels/list_hotel_booking_options/backends.json +16 -0
  70. package/examples/google-hotels/list_hotel_booking_options/index.ts +123 -0
  71. package/examples/google-hotels/list_hotel_booking_options/package.json +9 -0
  72. package/examples/google-hotels/list_hotel_booking_options/parser.ts +308 -0
  73. package/examples/google-hotels/list_hotel_booking_options/playbook.yaml +95 -0
  74. package/examples/google-hotels/list_hotel_booking_options/request-transform.ts +77 -0
  75. package/examples/google-hotels/list_hotel_booking_options/workflow.json +67 -0
  76. package/examples/google-hotels/search_hotel_web_links/backends.json +16 -0
  77. package/examples/google-hotels/search_hotel_web_links/index.ts +90 -0
  78. package/examples/google-hotels/search_hotel_web_links/package.json +9 -0
  79. package/examples/google-hotels/search_hotel_web_links/parser.ts +96 -0
  80. package/examples/google-hotels/search_hotel_web_links/playbook.yaml +53 -0
  81. package/examples/google-hotels/search_hotel_web_links/request-transform.ts +17 -0
  82. package/examples/google-hotels/search_hotel_web_links/workflow.json +43 -0
  83. package/examples/google-hotels/search_hotels/backends.json +16 -0
  84. package/examples/google-hotels/search_hotels/index.ts +32 -102
  85. package/examples/google-hotels/search_hotels/parser.ts +237 -216
  86. package/examples/google-hotels/search_hotels/playbook.yaml +177 -42
  87. package/examples/google-hotels/search_hotels/request-transform.ts +101 -170
  88. package/examples/google-hotels/search_hotels/workflow.json +24 -73
  89. package/examples/google-hotels/suggest_hotel_destinations/backends.json +16 -0
  90. package/examples/google-hotels/{autocomplete_hotel_location → suggest_hotel_destinations}/index.ts +30 -19
  91. package/examples/google-hotels/suggest_hotel_destinations/package.json +9 -0
  92. package/examples/google-hotels/suggest_hotel_destinations/parser.ts +138 -0
  93. package/examples/google-hotels/suggest_hotel_destinations/playbook.yaml +47 -0
  94. package/examples/google-hotels/suggest_hotel_destinations/request-transform.ts +33 -0
  95. package/examples/google-hotels/suggest_hotel_destinations/workflow.json +44 -0
  96. package/examples/southwest/README.md +31 -70
  97. package/examples/southwest/get_account_details/backends.json +22 -0
  98. package/examples/southwest/get_account_details/credentials.manifest.json +17 -0
  99. package/examples/southwest/get_account_details/index.ts +138 -0
  100. package/examples/{google-hotels/_shared → southwest/get_account_details}/package.json +2 -2
  101. package/examples/southwest/get_account_details/parser.ts +136 -0
  102. package/examples/southwest/get_account_details/playbook.yaml +19 -0
  103. package/examples/southwest/get_account_details/workflow.json +93 -0
  104. package/examples/southwest/get_flight_status/backends.json +21 -0
  105. package/examples/southwest/get_flight_status/index.ts +130 -0
  106. package/examples/southwest/get_flight_status/package.json +9 -0
  107. package/examples/southwest/get_flight_status/parser.ts +138 -0
  108. package/examples/southwest/get_flight_status/playbook.yaml +58 -0
  109. package/examples/southwest/get_flight_status/workflow.json +77 -0
  110. package/examples/southwest/get_low_fare_calendar/backends.json +21 -0
  111. package/examples/southwest/get_low_fare_calendar/index.ts +134 -0
  112. package/examples/southwest/get_low_fare_calendar/package.json +9 -0
  113. package/examples/southwest/get_low_fare_calendar/parser.ts +107 -0
  114. package/examples/southwest/get_low_fare_calendar/playbook.yaml +41 -0
  115. package/examples/southwest/get_low_fare_calendar/workflow.json +81 -0
  116. package/examples/southwest/list_upcoming_trips/backends.json +22 -0
  117. package/examples/southwest/list_upcoming_trips/credentials.manifest.json +17 -0
  118. package/examples/southwest/list_upcoming_trips/index.ts +123 -0
  119. package/examples/southwest/list_upcoming_trips/package.json +9 -0
  120. package/examples/southwest/list_upcoming_trips/parser.ts +160 -0
  121. package/examples/southwest/list_upcoming_trips/playbook.yaml +24 -0
  122. package/examples/southwest/list_upcoming_trips/workflow.json +78 -0
  123. package/examples/southwest/search_flights/backends.json +21 -0
  124. package/examples/southwest/search_flights/index.ts +150 -0
  125. package/examples/southwest/search_flights/package.json +9 -0
  126. package/examples/southwest/search_flights/parser.ts +214 -0
  127. package/examples/southwest/search_flights/playbook.yaml +52 -0
  128. package/examples/southwest/search_flights/workflow.json +88 -0
  129. package/package.json +1 -1
  130. package/prompts/audit-agent.md +2 -1
  131. package/prompts/build-planning.md +22 -1
  132. package/prompts/compile-agent.md +66 -53
  133. package/prompts/prereq-builder.md +3 -1
  134. package/prompts/tool-planning.md +2 -0
  135. package/src/cli.ts +8 -3
  136. package/src/imprint/audit.ts +337 -44
  137. package/src/imprint/backend-cache.ts +114 -0
  138. package/src/imprint/backend-ladder.ts +74 -24
  139. package/src/imprint/bot-defense.ts +12 -0
  140. package/src/imprint/build-plan.ts +346 -53
  141. package/src/imprint/cdp-browser-fetch.ts +96 -43
  142. package/src/imprint/cdp-jar-cache.ts +6 -5
  143. package/src/imprint/chromium.ts +34 -0
  144. package/src/imprint/codex-cli-compile.ts +13 -2
  145. package/src/imprint/compile-agent.ts +3 -1
  146. package/src/imprint/compile-tools.ts +715 -138
  147. package/src/imprint/compile.ts +41 -9
  148. package/src/imprint/concurrency.ts +26 -3
  149. package/src/imprint/cron.ts +0 -3
  150. package/src/imprint/endpoint-key.ts +23 -0
  151. package/src/imprint/llm-url.ts +69 -0
  152. package/src/imprint/llm.ts +366 -47
  153. package/src/imprint/login.ts +83 -75
  154. package/src/imprint/mcp-compile-server.ts +4 -1
  155. package/src/imprint/mcp-server.ts +51 -16
  156. package/src/imprint/param-grounding.ts +61 -52
  157. package/src/imprint/probe-backends.ts +21 -115
  158. package/src/imprint/redact.ts +17 -15
  159. package/src/imprint/request-capture.ts +94 -0
  160. package/src/imprint/runtime.ts +1 -78
  161. package/src/imprint/session-diff.ts +14 -1
  162. package/src/imprint/stealth-fetch.ts +30 -20
  163. package/src/imprint/stealth-token-cache.ts +2 -2
  164. package/src/imprint/teach-plan.ts +2 -0
  165. package/src/imprint/teach-state.ts +14 -9
  166. package/src/imprint/teach.ts +41 -7
  167. package/src/imprint/telemetry.ts +3 -0
  168. package/src/imprint/tool-candidates.ts +8 -7
  169. package/src/imprint/tool-plan.ts +29 -3
  170. package/src/imprint/tracing.ts +18 -2
  171. package/examples/google-flights/_shared/batchexecute.ts +0 -63
  172. package/examples/google-flights/_shared/flights_request.ts +0 -97
  173. package/examples/google-flights/get_flight_booking_details/index.ts +0 -159
  174. package/examples/google-flights/get_flight_booking_details/parser.ts +0 -182
  175. package/examples/google-flights/get_flight_booking_details/playbook.yaml +0 -138
  176. package/examples/google-flights/get_flight_booking_details/request-transform.ts +0 -86
  177. package/examples/google-flights/get_flight_booking_details/workflow.json +0 -98
  178. package/examples/google-flights/get_flight_calendar_prices/request-transform.ts +0 -31
  179. package/examples/google-flights/lookup_airport/parser.ts +0 -66
  180. package/examples/google-flights/lookup_airport/playbook.yaml +0 -47
  181. package/examples/google-flights/lookup_airport/request-transform.ts +0 -20
  182. package/examples/google-hotels/_shared/batchexecute.ts +0 -73
  183. package/examples/google-hotels/_shared/freq.ts +0 -158
  184. package/examples/google-hotels/autocomplete_hotel_location/parser.ts +0 -71
  185. package/examples/google-hotels/autocomplete_hotel_location/playbook.yaml +0 -36
  186. package/examples/google-hotels/autocomplete_hotel_location/request-transform.ts +0 -37
  187. package/examples/google-hotels/autocomplete_hotel_location/workflow.json +0 -36
  188. package/examples/google-hotels/get_hotel_booking_options/index.ts +0 -143
  189. package/examples/google-hotels/get_hotel_booking_options/parser.ts +0 -271
  190. package/examples/google-hotels/get_hotel_booking_options/playbook.yaml +0 -154
  191. package/examples/google-hotels/get_hotel_booking_options/request-transform.ts +0 -154
  192. package/examples/google-hotels/get_hotel_booking_options/workflow.json +0 -84
  193. package/examples/google-hotels/get_hotel_reviews/request-transform.ts +0 -42
  194. package/examples/southwest/search_southwest_flights/backends.json +0 -23
  195. package/examples/southwest/search_southwest_flights/cron.json +0 -19
  196. package/examples/southwest/search_southwest_flights/index.ts +0 -127
  197. package/examples/southwest/search_southwest_flights/playbook.yaml +0 -46
  198. package/examples/southwest/search_southwest_flights/workflow.json +0 -71
  199. /package/examples/google-flights/{get_flight_booking_details → get_flight_booking_options}/package.json +0 -0
  200. /package/examples/google-flights/{lookup_airport → get_flight_location_details}/package.json +0 -0
  201. /package/examples/google-hotels/{autocomplete_hotel_location → get_hotel_details}/package.json +0 -0
  202. /package/examples/google-hotels/{get_hotel_booking_options → get_hotel_photos}/package.json +0 -0
@@ -1,113 +1,268 @@
1
- // Adapter around the shared FlightsFrontendService body builder.
2
- // The tool exposes flat snake_case params (origin, destination, departure_date,
3
- // max_stops, …); the shared encoder consumes a structured camelCase shape
4
- // ({ tripType, legs:[{origin,dest,date,times,stops,includeAirlines,duration}],
5
- // maxPrice, bags }). We map between them here and delegate the byte-for-byte
6
- // positional encoding to the shared module (required reuse).
7
- import { transform as sharedTransform } from '../_shared/flights_request.ts';
8
-
9
- type Params = Record<string, string | number | boolean | undefined | null>;
10
-
11
- function mapTripType(v: unknown): number {
12
- if (v == null || v === '') return 1;
13
- if (typeof v === 'number') return v;
14
- const s = String(v).trim().toLowerCase().replace(/[\s-]+/g, '_');
15
- if (s === 'one_way' || s === 'oneway' || s === '2') return 2;
16
- if (s === 'multi_city' || s === 'multicity' || s === '3') return 3;
17
- return 1; // round_trip
18
- }
19
-
20
- // User semantics (per likelyParam): 0=nonstop, 1=≤1 stop, 2=≤2 stops, 3=any.
21
- // Google wire encoding: 1=nonstop, 2=≤1, 3=≤2, 0=any.
22
- function mapStops(v: unknown): number {
23
- switch (Number(v)) {
24
- case 0:
1
+ import { transform as transportTransform } from '../_shared/google_flights_transport.ts';
2
+
3
+ type Params = Record<string, string | number | boolean>;
4
+
5
+ type MultiCityLeg = { origin: string; destination: string; date: string };
6
+ type SegmentTuple = [string, string, string, null, string, string];
7
+
8
+ function asString(params: Params | undefined, key: string, fallback = ''): string {
9
+ const value = params?.[key];
10
+ return value === undefined || value === null ? fallback : String(value);
11
+ }
12
+
13
+ function asNumber(params: Params | undefined, key: string, fallback: number): number {
14
+ const value = params?.[key];
15
+ if (typeof value === 'number' && Number.isFinite(value)) return value;
16
+ if (typeof value === 'string' && value.trim() !== '') {
17
+ const parsed = Number(value);
18
+ if (Number.isFinite(parsed)) return parsed;
19
+ }
20
+ return fallback;
21
+ }
22
+
23
+ function location(value: string): [string, number] {
24
+ const trimmed = value.trim();
25
+ if (trimmed.startsWith('/m/')) return [trimmed, 5];
26
+ return [trimmed.toUpperCase(), 0];
27
+ }
28
+
29
+ function locGroup(value: string): [[[string, number]]] {
30
+ return [[location(value)]];
31
+ }
32
+
33
+ function tripTypeCode(value: string): number {
34
+ switch (value.trim().toLowerCase()) {
35
+ case 'one_way':
36
+ case 'one-way':
37
+ case 'one way':
38
+ case '2':
39
+ return 2;
40
+ case 'multi_city':
41
+ case 'multi-city':
42
+ case 'multi city':
43
+ case '3':
44
+ return 3;
45
+ case 'round_trip':
46
+ case 'round-trip':
47
+ case 'round trip':
48
+ case '1':
49
+ default:
50
+ return 1;
51
+ }
52
+ }
53
+
54
+ function stopCode(value: string): number {
55
+ switch (value.trim().toLowerCase()) {
56
+ case 'nonstop_only':
57
+ case 'nonstop':
58
+ case 'non_stop':
25
59
  return 1;
26
- case 1:
60
+ case 'one_stop_or_fewer':
61
+ case 'one stop or fewer':
27
62
  return 2;
28
- case 2:
63
+ case 'two_stops_or_fewer':
64
+ case 'two stops or fewer':
29
65
  return 3;
66
+ case 'any':
30
67
  default:
31
- return 0; // any (default / 3)
68
+ return 0;
32
69
  }
33
70
  }
34
71
 
35
- // "6-23" -> [depMin, depMax, arrMin, arrMax]; arrival defaults to full day.
36
- function parseTimes(v: unknown): number[] | null {
37
- if (v == null || v === '') return null;
38
- const m = /^(\d{1,2})-(\d{1,2})$/.exec(String(v).trim());
39
- if (!m) return null;
40
- return [Number(m[1]), Number(m[2]), 0, 23];
72
+ function parseTimeRange(value: string): [number, number] | null {
73
+ const match = value.trim().match(/^(\d{1,2})(?::\d{2})?-(\d{1,2})(?::\d{2})?$/);
74
+ if (!match) return null;
75
+ const start = Number(match[1]);
76
+ const end = Number(match[2]);
77
+ if (!Number.isFinite(start) || !Number.isFinite(end)) return null;
78
+ return [start, end];
41
79
  }
42
80
 
43
- function parseAirlines(v: unknown): string[] | null {
44
- if (v == null || v === '') return null;
45
- const includeAirlines = String(v)
46
- .split(',')
47
- .map((x) => x.trim())
48
- .filter(Boolean)
49
- .map((p) => p.toUpperCase());
50
- return includeAirlines.length ? includeAirlines : null;
81
+ function airlineList(value: string): string[] | null {
82
+ const items = value.split(',').map((item) => item.trim().toUpperCase()).filter(Boolean);
83
+ return items.length > 0 ? items : null;
51
84
  }
52
85
 
53
- function num(v: unknown): number | undefined {
54
- if (v == null || v === '') return undefined;
55
- const n = Number(v);
56
- return Number.isFinite(n) && n > 0 ? n : undefined;
86
+ function normalizeSegment(value: unknown): SegmentTuple | null {
87
+ if (Array.isArray(value)) {
88
+ const [origin, date, destination, ignored, carrier, flightNumber] = value;
89
+ if (typeof origin === 'string' && typeof date === 'string' && typeof destination === 'string' && typeof carrier === 'string' && String(flightNumber)) {
90
+ return [origin, date, destination, ignored === null ? null : null, carrier, String(flightNumber)];
91
+ }
92
+ }
93
+ if (value && typeof value === 'object') {
94
+ const obj = value as Record<string, unknown>;
95
+ const origin = obj.origin;
96
+ const date = obj.date ?? obj.departureDate;
97
+ const destination = obj.destination;
98
+ const carrier = obj.carrier ?? obj.carrierCode;
99
+ const flightNumber = obj.flightNumber ?? obj.flight_number;
100
+ if (typeof origin === 'string' && typeof date === 'string' && typeof destination === 'string' && typeof carrier === 'string' && flightNumber != null) {
101
+ return [origin, date, destination, null, carrier, String(flightNumber)];
102
+ }
103
+ }
104
+ return null;
57
105
  }
58
106
 
59
- export function transform(
60
- method: string,
61
- url: string,
62
- responses: Record<string, any>,
63
- params?: Params,
64
- ): { url: string; body: string } {
65
- const p: Params = params ?? {};
66
- const requestedTripType = mapTripType(p.trip_type);
67
- const hasReturnDate = p.return_date != null && String(p.return_date).trim() !== '';
68
- const tripType = requestedTripType === 1 && !hasReturnDate ? 2 : requestedTripType;
69
- const stops = p.max_stops != null && p.max_stops !== '' ? mapStops(p.max_stops) : 0;
70
- const includeAirlines = parseAirlines(p.airlines);
71
- const maxDur = num(p.max_duration);
72
- const duration = maxDur != null ? [maxDur] : null;
73
-
74
- const origin = p.origin != null ? String(p.origin) : '';
75
- const destination = p.destination != null ? String(p.destination) : '';
76
-
77
- const legs: any[] = [
78
- {
79
- origin,
80
- dest: destination,
81
- date: p.departure_date ? String(p.departure_date) : null,
82
- times: parseTimes(p.outbound_times),
83
- stops,
84
- includeAirlines,
85
- duration,
86
- },
107
+ function parseSelectedFlights(raw: unknown): SegmentTuple[] {
108
+ if (Array.isArray(raw)) return raw.map(normalizeSegment).filter((item): item is SegmentTuple => Boolean(item));
109
+ if (typeof raw !== 'string') return [];
110
+ const trimmed = raw.trim();
111
+ if (!trimmed) return [];
112
+ try {
113
+ return parseSelectedFlights(JSON.parse(trimmed));
114
+ } catch {
115
+ return [];
116
+ }
117
+ }
118
+
119
+ function sameCode(left: string, right: string): boolean {
120
+ return left.trim().toUpperCase() === right.trim().toUpperCase();
121
+ }
122
+
123
+ function dateDeltaDays(left: string, right: string): number | null {
124
+ const leftTime = Date.parse(`${left}T00:00:00Z`);
125
+ const rightTime = Date.parse(`${right}T00:00:00Z`);
126
+ if (!Number.isFinite(leftTime) || !Number.isFinite(rightTime)) return null;
127
+ return Math.round((rightTime - leftTime) / 86_400_000);
128
+ }
129
+
130
+ function groupSelectedSegments(segments: SegmentTuple[]): SegmentTuple[][] {
131
+ const groups: SegmentTuple[][] = [];
132
+ for (const segment of segments) {
133
+ const current = groups[groups.length - 1];
134
+ const previous = current?.[current.length - 1];
135
+ const startsReturnToGroupOrigin = current ? sameCode(segment[2], current[0]![0]) : false;
136
+ const dateDelta = previous ? dateDeltaDays(previous[1], segment[1]) : null;
137
+ const continuesConnection = previous
138
+ && sameCode(segment[0], previous[2])
139
+ && (dateDelta === null || (dateDelta >= 0 && dateDelta <= 1))
140
+ && !startsReturnToGroupOrigin;
141
+ if (current && continuesConnection) {
142
+ current.push(segment);
143
+ } else {
144
+ groups.push([segment]);
145
+ }
146
+ }
147
+ return groups;
148
+ }
149
+
150
+ function leg(
151
+ origin: string,
152
+ destination: string,
153
+ date: string,
154
+ stops: number,
155
+ airlines: string[] | null,
156
+ timeRange: [number, number] | null,
157
+ bags: number,
158
+ legFlag = 3,
159
+ selectedSegments: SegmentTuple[] | null = null,
160
+ ): unknown[] {
161
+ return [
162
+ locGroup(origin),
163
+ locGroup(destination),
164
+ timeRange,
165
+ stops,
166
+ airlines,
167
+ null,
168
+ date,
169
+ bags > 0 ? [bags * 90] : null,
170
+ selectedSegments,
171
+ null,
172
+ null,
173
+ null,
174
+ null,
175
+ null,
176
+ stops || airlines || timeRange || bags > 0 ? 1 : legFlag,
87
177
  ];
178
+ }
88
179
 
89
- // Append a return leg for round-trip / multi-city when a return date exists.
90
- if (tripType !== 2 && p.return_date) {
91
- legs.push({
92
- origin: destination,
93
- dest: origin,
94
- date: String(p.return_date),
95
- times: parseTimes(p.return_times),
96
- stops,
97
- includeAirlines,
98
- duration,
180
+ function parseMultiCityLegs(value: string): MultiCityLeg[] {
181
+ const legs: MultiCityLeg[] = [];
182
+ for (const part of value.split(';').map((item) => item.trim()).filter(Boolean)) {
183
+ const [origin, destination, date] = part.split(',').map((item) => item.trim());
184
+ if (origin && destination && date) legs.push({ origin, destination, date });
185
+ }
186
+ return legs;
187
+ }
188
+
189
+ function buildInner(params?: Params): unknown[] {
190
+ const itinerary = asString(params, 'itinerary', '');
191
+ let tripCode = itinerary.trim() ? 3 : tripTypeCode(asString(params, 'trip_type', 'round_trip'));
192
+ if (tripCode === 1 && !asString(params, 'return_date', '').trim()) tripCode = 2;
193
+ const adults = Math.max(1, asNumber(params, 'adults', 1));
194
+ const bags = Math.max(0, asNumber(params, 'bags', 0));
195
+ const stops = stopCode(asString(params, 'stops', 'any'));
196
+ const airlines = airlineList(asString(params, 'airlines', ''));
197
+ const maxPrice = asNumber(params, 'max_price', 0);
198
+ const maxDuration = asNumber(params, 'max_duration_minutes', 0);
199
+ const outboundTimeRange = parseTimeRange(asString(params, 'outbound_time_range', ''));
200
+ const returnTimeRange = parseTimeRange(asString(params, 'return_time_range', ''));
201
+ const selectedFlightGroups = groupSelectedSegments(parseSelectedFlights(params?.selected_flights));
202
+ const selectionToken = asString(params, 'selection_token', '');
203
+
204
+ let legs: unknown[];
205
+ if (tripCode === 3) {
206
+ const parsedLegs = parseMultiCityLegs(itinerary);
207
+ const sourceLegs = parsedLegs.length > 0
208
+ ? parsedLegs
209
+ : [{ origin: asString(params, 'origin', 'SJC'), destination: asString(params, 'destination', 'SAN'), date: asString(params, 'departure_date', '2026-07-12') }];
210
+ legs = sourceLegs.map((item, index) => {
211
+ const selectedSegments = selectedFlightGroups[index];
212
+ return leg(item.origin, item.destination, item.date, stops, airlines, outboundTimeRange, bags, 1, selectedSegments ?? null);
99
213
  });
214
+ } else {
215
+ const origin = asString(params, 'origin', 'SJC');
216
+ const destination = asString(params, 'destination', 'SAN');
217
+ const departureDate = asString(params, 'departure_date', '2026-07-12');
218
+ legs = [leg(origin, destination, departureDate, stops, airlines, outboundTimeRange, bags, 3)];
219
+ if (tripCode === 1) {
220
+ const returnDate = asString(params, 'return_date', '2026-07-16');
221
+ legs.push(leg(destination, origin, returnDate, stops, airlines, returnTimeRange, bags, 1));
222
+ }
100
223
  }
101
224
 
102
- const carryOn = num(p.carry_on_bags);
103
- const mapped: Record<string, any> = {
104
- tripType,
225
+ const filters = [
226
+ null,
227
+ null,
228
+ tripCode,
229
+ null,
230
+ [],
231
+ adults,
232
+ [adults, 0, 0, 0],
233
+ maxPrice > 0 ? [null, maxPrice] : null,
234
+ null,
235
+ null,
236
+ maxDuration > 0 ? [1, 1] : null,
237
+ null,
238
+ null,
105
239
  legs,
106
- maxPrice: num(p.max_price),
107
- // CONFIG[10] wire form is [1, <carry-on count>]; shared builder emits
108
- // [carryOn, checked], so map count -> checked slot, constant 1 -> first.
109
- bags: carryOn != null ? { carryOn: 1, checked: carryOn } : undefined,
110
- };
240
+ null,
241
+ null,
242
+ null,
243
+ 1,
244
+ ];
245
+
246
+ if (selectionToken && selectedFlightGroups.length > 0) return [[null, selectionToken], filters, 0, 0, 0, 1];
247
+ return [[], filters, 0, 0, 0, 1];
248
+ }
111
249
 
112
- return sharedTransform(method, url, responses, mapped);
250
+ export function transform(
251
+ method: string,
252
+ url: string,
253
+ responses: unknown[],
254
+ params?: Params,
255
+ ): { url: string; body: string; headers: Record<string, string> } {
256
+ return transportTransform(method, url, responses, {
257
+ fReq: [null, JSON.stringify(buildInner(params))],
258
+ sourcePath: '/travel/flights',
259
+ referer: 'https://www.google.com/travel/flights/search?tfs=CBwQAhoeEgoyMDI2LTA2LTA4agcIARIDU0pDcgcIARIDU0FOGh4SCjIwMjYtMDYtMTFqBwgBEgNTQU5yBwgBEgNTSkNAAUgBcAGCAQsI____________AZgBAQ',
260
+ headers: {
261
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
262
+ 'X-Same-Domain': '1',
263
+ 'Accept-Language': 'en-US,en;q=0.9',
264
+ 'sec-ch-ua-full-version': '"148.0.7778.96"',
265
+ 'x-goog-ext-259736195-jspb': '["en-US","US","USD",2,null,[420],null,null,7,[]]',
266
+ },
267
+ }) as { url: string; body: string; headers: Record<string, string> };
113
268
  }
@@ -1,114 +1,138 @@
1
1
  {
2
2
  "toolName": "search_flights",
3
- "site": "google-flights",
4
3
  "intent": {
5
- "description": "Search Google Flights for itineraries between two airports with dates, trip type, and filters (stops, airlines, price, times, duration, bags).",
6
- "userSaid": "searched for a round trip flight; searched for a one way flight; played with the stops and the airlines filters; added bags; played with the price and time filters; played with the duration filter; did a multi city flight query"
4
+ "description": "Search Google Flights for one-way, round-trip, or multi-city flight options with filters.",
5
+ "userSaid": "searched for a round trip flight; searched for a one way flight; played with the stops and the airlines filters; added bags; played with the price and time filters; played with the duration filter"
7
6
  },
7
+ "site": "google-flights",
8
8
  "parameters": [
9
+ {
10
+ "name": "trip_type",
11
+ "type": "string",
12
+ "description": "Ticket type such as round_trip, one_way, or multi_city.",
13
+ "default": "round_trip",
14
+ "verified": false,
15
+ "verifyNote": "annotated"
16
+ },
9
17
  {
10
18
  "name": "origin",
11
19
  "type": "string",
12
- "description": "Origin airport/city IATA code, e.g. SJC",
20
+ "description": "Origin airport code, city code, or place identifier for one-way and round-trip searches.",
21
+ "default": "SJC",
13
22
  "verified": false,
14
23
  "verifyNote": "annotated"
15
24
  },
16
25
  {
17
26
  "name": "destination",
18
27
  "type": "string",
19
- "description": "Destination airport/city IATA code, e.g. SAN",
28
+ "description": "Destination airport code, city code, or place identifier for one-way and round-trip searches.",
29
+ "default": "SAN",
20
30
  "verified": false,
21
31
  "verifyNote": "annotated"
22
32
  },
23
33
  {
24
34
  "name": "departure_date",
25
35
  "type": "string",
26
- "description": "Outbound date in YYYY-MM-DD",
36
+ "description": "Departure date in YYYY-MM-DD format.",
37
+ "default": "2026-07-12",
27
38
  "verified": false,
28
39
  "verifyNote": "annotated"
29
40
  },
30
41
  {
31
42
  "name": "return_date",
32
43
  "type": "string",
33
- "description": "Return date in YYYY-MM-DD (omit/empty for one way)",
34
- "default": "",
44
+ "description": "Return date in YYYY-MM-DD format for round-trip searches.",
45
+ "default": "2026-07-16",
35
46
  "verified": false,
36
47
  "verifyNote": "annotated"
37
48
  },
38
49
  {
39
- "name": "trip_type",
50
+ "name": "itinerary",
40
51
  "type": "string",
41
- "description": "round_trip, one_way, or multi_city",
42
- "default": "round_trip",
52
+ "description": "Multi-city itinerary as semicolon-separated origin,destination,date legs, such as SFO,LAX,2026-09-01;LAX,JFK,2026-09-04. Supplying this value selects multi-city search semantics.",
53
+ "default": "",
43
54
  "verified": false,
44
55
  "verifyNote": "annotated"
45
56
  },
46
57
  {
47
- "name": "max_stops",
48
- "type": "number",
49
- "description": "Max stops: 0=nonstop, 1=<=1 stop, 2=<=2 stops, 3=any",
50
- "default": 3,
51
- "verified": false,
52
- "verifyNote": "annotated"
58
+ "name": "selection_token",
59
+ "type": "string",
60
+ "description": "Selection token from a prior search_flights result. For staged round-trip or multi-city selection, pass this with selected_flights to fetch the next leg options.",
61
+ "default": "",
62
+ "verified": true
53
63
  },
54
64
  {
55
- "name": "airlines",
65
+ "name": "selected_flights",
56
66
  "type": "string",
57
- "description": "Comma-separated alliance (ONEWORLD/SKYTEAM/STAR_ALLIANCE) or 2-letter carrier codes (e.g. AS,WN). Empty = no filter",
67
+ "description": "JSON array of already selected leg tuples from a prior search_flights result. For staged round-trip or multi-city selection, pass this with selection_token to fetch the next leg options and emit a complete selected_flights array.",
58
68
  "default": "",
59
- "verified": false,
60
- "verifyNote": "annotated"
69
+ "verified": true
61
70
  },
62
71
  {
63
- "name": "max_price",
72
+ "name": "adults",
64
73
  "type": "number",
65
- "description": "Maximum total price in USD (0 = no filter)",
66
- "default": 0,
74
+ "description": "Number of adult passengers.",
75
+ "default": 1,
67
76
  "verified": false,
68
77
  "verifyNote": "annotated"
69
78
  },
70
79
  {
71
- "name": "outbound_times",
80
+ "name": "stops",
72
81
  "type": "string",
73
- "description": "Outbound departure window in hours, e.g. '6-23' (empty = no filter)",
74
- "default": "",
82
+ "description": "Stops filter for routes with both nonstop and connecting options, such as any, nonstop_only, one_stop_or_fewer, or two_stops_or_fewer.",
83
+ "default": "any",
75
84
  "verified": false,
76
85
  "verifyNote": "annotated"
77
86
  },
78
87
  {
79
- "name": "return_times",
88
+ "name": "airlines",
80
89
  "type": "string",
81
- "description": "Return departure window in hours, e.g. '6-23' (empty = no filter)",
90
+ "description": "Comma-separated airline or alliance codes to include, such as AS, AA, WN, ONEWORLD, SKYTEAM, or STAR_ALLIANCE.",
82
91
  "default": "",
83
92
  "verified": false,
84
93
  "verifyNote": "annotated"
85
94
  },
86
95
  {
87
- "name": "max_duration",
96
+ "name": "bags",
97
+ "type": "number",
98
+ "description": "Number of bags to include in fare filtering.",
99
+ "default": 0,
100
+ "verified": false,
101
+ "verifyNote": "annotated"
102
+ },
103
+ {
104
+ "name": "max_price",
88
105
  "type": "number",
89
- "description": "Maximum total trip duration in minutes, e.g. 540 (0 = no filter)",
106
+ "description": "Maximum fare price in USD.",
90
107
  "default": 0,
91
108
  "verified": false,
92
109
  "verifyNote": "annotated"
93
110
  },
94
111
  {
95
- "name": "carry_on_bags",
112
+ "name": "outbound_time_range",
113
+ "type": "string",
114
+ "description": "Outbound departure or arrival time constraints encoded as start and end hours, such as 2-21.",
115
+ "default": "",
116
+ "verified": false,
117
+ "verifyNote": "annotated"
118
+ },
119
+ {
120
+ "name": "max_duration_minutes",
96
121
  "type": "number",
97
- "description": "Number of carry-on bags to filter/price by (0 = no filter)",
122
+ "description": "Maximum flight duration in minutes.",
98
123
  "default": 0,
99
124
  "verified": false,
100
125
  "verifyNote": "annotated"
101
126
  }
102
127
  ],
103
128
  "bootstrap": {
104
- "url": "https://www.google.com/travel/flights",
129
+ "url": "https://www.google.com/travel/flights/search?tfs=CBwQAhoeEgoyMDI2LTA2LTA4agcIARIDU0pDcgcIARIDU0FOGh4SCjIwMjYtMDYtMTFqBwgBEgNTQU5yBwgBEgNTSkNAAUgBcAGCAQsI____________AZgBAQ",
105
130
  "waitUntil": "domcontentloaded",
106
- "timeoutMs": 30000,
107
131
  "captures": [
108
132
  {
109
133
  "source": "html_regex",
110
134
  "name": "f_sid",
111
- "pattern": "\"FdrFJe\":\"([^\"]+)\"",
135
+ "pattern": "\"FdrFJe\":\"(-?\\d+)\"",
112
136
  "group": 1,
113
137
  "required": true,
114
138
  "capability": "browser_bootstrap"
@@ -126,18 +150,20 @@
126
150
  "requests": [
127
151
  {
128
152
  "method": "POST",
129
- "url": "https://www.google.com/_/FlightsFrontendUi/data/travel.frontend.flights.FlightsFrontendService/GetShoppingResults?f.sid=${state.f_sid}&bl=${state.bl}&hl=en-US&soc-app=162&soc-platform=1&soc-device=1&_reqid=1708023&rt=c",
153
+ "url": "https://www.google.com/_/FlightsFrontendUi/data/travel.frontend.flights.FlightsFrontendService/GetShoppingResults?f.sid=${state.f_sid}&bl=${state.bl}&hl=en-US&soc-app=162&soc-platform=1&soc-device=1&_reqid=${generated.nonce}&rt=c",
130
154
  "headers": {
131
155
  "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
132
156
  "X-Same-Domain": "1",
133
- "Referer": "https://www.google.com/travel/flights",
157
+ "Referer": "https://www.google.com/travel/flights/search?tfs=CBwQAhoeEgoyMDI2LTA2LTA4agcIARIDU0pDcgcIARIDU0FOGh4SCjIwMjYtMDYtMTFqBwgBEgNTQU5yBwgBEgNTSkNAAUgBcAGCAQsI____________AZgBAQ",
158
+ "Accept-Language": "en-US,en;q=0.9",
159
+ "sec-ch-ua-full-version": "\"148.0.7778.96\"",
134
160
  "x-goog-ext-259736195-jspb": "[\"en-US\",\"US\",\"USD\",2,null,[420],null,null,7,[]]"
135
161
  },
136
- "body": "f.req=${param.origin}|${param.destination}|${param.departure_date}|${param.return_date}|${param.trip_type}|${param.max_stops}|${param.airlines}|${param.max_price}|${param.outbound_times}|${param.return_times}|${param.max_duration}|${param.carry_on_bags}&",
162
+ "body": "trip_type=${param.trip_type}&origin=${param.origin}&destination=${param.destination}&departure_date=${param.departure_date}&return_date=${param.return_date}&itinerary=${param.itinerary}&selection_token=${param.selection_token}&selected_flights=${param.selected_flights}&adults=${param.adults}&stops=${param.stops}&airlines=${param.airlines}&bags=${param.bags}&max_price=${param.max_price}&outbound_time_range=${param.outbound_time_range}&max_duration_minutes=${param.max_duration_minutes}",
137
163
  "effect": "safe"
138
164
  }
139
165
  ],
140
- "requestTransformModule": "./request-transform.ts",
141
166
  "parserModule": "./parser.ts",
167
+ "requestTransformModule": "./request-transform.ts",
142
168
  "liveVerified": true
143
169
  }
@@ -0,0 +1,27 @@
1
+ {
2
+ "probedAt": "2026-07-01T01:16:12.910Z",
3
+ "imprintVersion": "0.5.0",
4
+ "schemaVersion": 2,
5
+ "workflowHash": "7d73e606e5380f03e1188a8d91e9c76208d7df316d59d020cf87a41c97d1064d",
6
+ "capabilityHash": "5fc16811cd65aff7afee349ddca05c806a65c9c2c96948192ea1bafba9284c38",
7
+ "preferredOrder": [
8
+ "cdp-replay"
9
+ ],
10
+ "results": {
11
+ "fetch": {
12
+ "outcome": "failed",
13
+ "durationMs": 23,
14
+ "error": "STATE_MISSING",
15
+ "detail": "STATE_MISSING: Workflow placeholder ${state.bl} but state \"bl\" has not been captured yet"
16
+ },
17
+ "fetch-bootstrap": {
18
+ "outcome": "forbidden",
19
+ "durationMs": 30307,
20
+ "detail": "FORBIDDEN: fetch-bootstrap: cdp-minted jar did not validate; cdp-replay (in-page) required."
21
+ },
22
+ "cdp-replay": {
23
+ "outcome": "ok",
24
+ "durationMs": 525
25
+ }
26
+ }
27
+ }