Function bodies 269 total
getSites method · java · L51-L85 (35 LOC)src/main/java/com/matoe/service/SearchTargetService.java
public List<String> getSites(String agentName, String yamlDefault) {
List<SearchTargetEntity> dbTargets =
searchTargetRepo.findByAgentNameAndEnabledTrueOrderByPriorityAsc(agentName);
List<String> candidates;
Map<String, Integer> limits = new HashMap<>();
if (!dbTargets.isEmpty()) {
candidates = dbTargets.stream()
.map(SearchTargetEntity::getSiteUrl)
.collect(Collectors.toList());
for (SearchTargetEntity t : dbTargets) {
Integer rpm = t.getRateLimitRpm();
limits.put(t.getSiteUrl(), rpm == null || rpm <= 0 ? DEFAULT_RPM_LIMIT : rpm);
}
} else {
candidates = Arrays.stream(yamlDefault.split(","))
.map(String::trim)
.filter(s -> !s.isBlank())
.collect(Collectors.toList());
for (String s : candidates) limits.put(s, DEFAULT_RPM_LIMIT);
}
// Rate-limittryAcquire method · java · L92-L108 (17 LOC)src/main/java/com/matoe/service/SearchTargetService.java
private boolean tryAcquire(String siteUrl, int rpmLimit) {
long now = System.currentTimeMillis();
long windowMs = 60_000L;
long[] bucket = counters.compute(siteUrl, (k, current) -> {
if (current == null || now - current[0] >= windowMs) {
return new long[]{now, 0L};
}
return current;
});
synchronized (bucket) {
if (bucket[1] < rpmLimit) {
bucket[1]++;
return true;
}
return false;
}
}TravelService class · java · L47-L375 (329 LOC)src/main/java/com/matoe/service/TravelService.java
public class TravelService {
private static final Logger log = LoggerFactory.getLogger(TravelService.class);
private final TravelPlannerAgent travelPlannerAgent;
private final AgentProgressService progressService;
private final LlmCostTrackingService costTracker;
private final ItineraryRepository repository;
private final ObjectMapper objectMapper;
private final ExecutorService agentExecutor;
/** May be null if Embabel autoconfig is excluded in a given profile. */
private final AgentPlatform agentPlatform;
public TravelService(
TravelPlannerAgent travelPlannerAgent,
AgentProgressService progressService,
LlmCostTrackingService costTracker,
ItineraryRepository repository,
ObjectMapper objectMapper,
@Qualifier("agentExecutor") ExecutorService agentExecutor,
@Autowired(required = false) AgentPlatform agentPlatform) {
this.travelPlannerAgent = travelPlannerAplanTrip method · java · L81-L110 (30 LOC)src/main/java/com/matoe/service/TravelService.java
public UnforgettableItinerary planTrip(TravelRequest request, String sessionId) {
TravelRequest enriched = withSessionId(request, sessionId);
boolean live = sessionId != null && !sessionId.isBlank();
emit(live, sessionId, "Orchestrator", "deployed", 5, "Initialising agent swarm...");
// Pre-flight budget check
if (sessionId != null && costTracker.isBudgetExceeded(sessionId)) {
log.warn("Session {} budget already exceeded — aborting", sessionId);
throw new RuntimeException("LLM budget ceiling exceeded for this session");
}
UnforgettableItinerary itinerary;
if (agentPlatform != null) {
itinerary = runViaEmbabelGoap(enriched, sessionId);
} else {
itinerary = runViaVirtualThreads(enriched, sessionId);
}
// Apply tiering to raw results
itinerary = applyTiering(itinerary, enriched);
// Persist
save(itinerary);
emit(lrunViaEmbabelGoap method · java · L121-L155 (35 LOC)src/main/java/com/matoe/service/TravelService.java
private UnforgettableItinerary runViaEmbabelGoap(TravelRequest request, String sessionId) {
try {
log.info("Running trip via Embabel AgentPlatform (GOAP planner)");
Map<String, Object> bindings = Map.of("travelRequest", request);
// AgentPlatform.runAgentFrom(Agent, ProcessOptions, Map) — the first
// parameter expects Embabel's Agent interface. TravelPlannerAgent is
// an @Agent-annotated POJO; Embabel discovers it via scanning but its
// runtime type doesn't implement Agent at the Java type level, so we
// call the method reflectively to let Embabel's internal routing handle
// the dispatch.
Object process = invokeRunAgentFrom(bindings);
if (process == null) {
log.warn("Embabel runAgentFrom returned null — falling back");
return runViaVirtualThreads(request, sessionId);
}
// process.run() — some invokeRunAgentFrom method · java · L164-L184 (21 LOC)src/main/java/com/matoe/service/TravelService.java
private Object invokeRunAgentFrom(Map<String, Object> bindings) throws Exception {
Method[] methods = agentPlatform.getClass().getMethods();
// 3-arg form: (Agent, ProcessOptions, Map)
for (Method m : methods) {
if (!"runAgentFrom".equals(m.getName())) continue;
Class<?>[] p = m.getParameterTypes();
if (p.length == 3 && Map.class.isAssignableFrom(p[2])) {
Object opts = resolveDefaultProcessOptions(p[1]);
return m.invoke(agentPlatform, travelPlannerAgent, opts, bindings);
}
}
// 2-arg form: (Agent, Map)
for (Method m : methods) {
if (!"runAgentFrom".equals(m.getName())) continue;
Class<?>[] p = m.getParameterTypes();
if (p.length == 2 && Map.class.isAssignableFrom(p[1])) {
return m.invoke(agentPlatform, travelPlannerAgent, bindings);
}
}
throw new NoSuchMethodException("No comparesolveDefaultProcessOptions method · java · L187-L200 (14 LOC)src/main/java/com/matoe/service/TravelService.java
private static Object resolveDefaultProcessOptions(Class<?> optsType) {
// @JvmField companion val → static field DEFAULT
try { return optsType.getField("DEFAULT").get(null); }
catch (ReflectiveOperationException ignored) {}
// Kotlin companion object accessor
try {
Object companion = optsType.getField("Companion").get(null);
return companion.getClass().getMethod("getDEFAULT").invoke(companion);
} catch (ReflectiveOperationException ignored) {}
// No-arg constructor
try { return optsType.getDeclaredConstructor().newInstance(); }
catch (ReflectiveOperationException ignored) {}
return null; // will pass null; Embabel may use its internal default
}Powered by Repobility — scan your code at https://repobility.com
runViaVirtualThreads method · java · L210-L248 (39 LOC)src/main/java/com/matoe/service/TravelService.java
private UnforgettableItinerary runViaVirtualThreads(TravelRequest request, String sessionId) {
log.info("Running trip via virtual-thread fan-out (no AgentPlatform bean)");
CompletableFuture<TravelIntelligence> intelligenceFuture =
CompletableFuture.supplyAsync(() -> travelPlannerAgent.gatherIntelligence(request), agentExecutor);
CompletableFuture<AccommodationResults> accommodationFuture =
CompletableFuture.supplyAsync(() -> travelPlannerAgent.searchAccommodations(request), agentExecutor);
CompletableFuture<TransportResults> transportFuture =
CompletableFuture.supplyAsync(() -> travelPlannerAgent.searchTransport(request), agentExecutor);
CompletableFuture<AttractionResults> attractionsFuture =
CompletableFuture.supplyAsync(() -> travelPlannerAgent.searchAttractions(request), agentExecutor);
CompletableFuture.allOf(
intelligenceFuture, accommodationFuture, transportFuture, awithSessionId method · java · L252-L260 (9 LOC)src/main/java/com/matoe/service/TravelService.java
private TravelRequest withSessionId(TravelRequest r, String sessionId) {
return new TravelRequest(
r.destination(), r.destinations(), r.startDate(), r.endDate(),
r.guestCount(), r.budgetMin(), r.budgetMax(), r.travelStyle(),
r.accommodationTypes(), r.transportTypes(), r.interestTags(),
r.orchestratorModel(), r.extractorModel(), r.originCity(),
sessionId
);
}applyTiering method · java · L264-L272 (9 LOC)src/main/java/com/matoe/service/TravelService.java
private UnforgettableItinerary applyTiering(UnforgettableItinerary it, TravelRequest request) {
List<AccommodationOption> tiered = tierAccommodations(it.accommodations(), request);
List<TransportOption> tieredTransport = tierTransport(it.transport(), request);
return new UnforgettableItinerary(
it.id(), it.destination(), it.startDate(), it.endDate(), it.guestCount(),
it.regionInsights(), tiered, tieredTransport, it.attractions(), it.variants(),
it.totalEstimatedCost(), it.weatherForecast(), it.currencyInfo(), it.createdAt()
);
}tierAccommodations method · java · L274-L287 (14 LOC)src/main/java/com/matoe/service/TravelService.java
private List<AccommodationOption> tierAccommodations(
List<AccommodationOption> list, TravelRequest request) {
if (list == null || list.isEmpty()) return List.of();
double mid = (request.budgetMax() - request.budgetMin()) / 2.0;
double budgetLine = mid * 0.7;
double luxuryLine = mid * 1.3;
return list.stream().map(a -> {
String tier = a.pricePerNight() <= budgetLine ? "budget"
: a.pricePerNight() <= luxuryLine ? "standard" : "luxury";
return new AccommodationOption(a.id(), a.type(), a.name(), a.pricePerNight(),
a.totalPrice(), a.rating(), a.location(), a.amenities(), a.bookingUrl(),
tier, a.source(), a.imageUrl());
}).collect(Collectors.toList());
}tierTransport method · java · L289-L302 (14 LOC)src/main/java/com/matoe/service/TravelService.java
private List<TransportOption> tierTransport(
List<TransportOption> list, TravelRequest request) {
if (list == null || list.isEmpty()) return List.of();
double avg = list.stream().mapToDouble(TransportOption::price).average().orElse(200);
double budgetLine = avg * 0.7;
double luxuryLine = avg * 1.3;
return list.stream().map(t -> {
String tier = t.price() <= budgetLine ? "budget"
: t.price() <= luxuryLine ? "standard" : "luxury";
return new TransportOption(t.id(), t.type(), t.provider(), t.departureTime(),
t.arrivalTime(), t.duration(), t.price(), t.stops(), t.bookingUrl(),
tier, t.source(), t.origin(), t.destination());
}).collect(Collectors.toList());
}getAllItineraries method · java · L306-L309 (4 LOC)src/main/java/com/matoe/service/TravelService.java
public List<UnforgettableItinerary> getAllItineraries() {
return repository.findAllByOrderByCreatedAtDesc().stream()
.map(this::toItinerary).collect(Collectors.toList());
}searchItineraries method · java · L311-L314 (4 LOC)src/main/java/com/matoe/service/TravelService.java
public List<UnforgettableItinerary> searchItineraries(String destination) {
return repository.findByDestinationContainingIgnoreCaseOrderByCreatedAtDesc(destination)
.stream().map(this::toItinerary).collect(Collectors.toList());
}getItinerary method · java · L316-L318 (3 LOC)src/main/java/com/matoe/service/TravelService.java
public UnforgettableItinerary getItinerary(String id) {
return repository.findById(id).map(this::toItinerary).orElse(null);
}Open data scored by Repobility · https://repobility.com
emit method · java · L322-L325 (4 LOC)src/main/java/com/matoe/service/TravelService.java
private void emit(boolean live, String sessionId, String agent,
String status, int progress, String message) {
if (live) progressService.update(sessionId, agent, status, progress, message);
}save method · java · L329-L346 (18 LOC)src/main/java/com/matoe/service/TravelService.java
private void save(UnforgettableItinerary it) {
try {
ItineraryEntity entity = new ItineraryEntity(
it.id(), it.destination(), it.startDate(), it.endDate(),
it.guestCount(), it.totalEstimatedCost(), it.createdAt(),
objectMapper.writeValueAsString(it.regionInsights()),
objectMapper.writeValueAsString(it.accommodations()),
objectMapper.writeValueAsString(it.transport())
);
entity.setAttractionsJson(objectMapper.writeValueAsString(it.attractions()));
entity.setVariantsJson(objectMapper.writeValueAsString(it.variants()));
entity.setWeatherJson(objectMapper.writeValueAsString(it.weatherForecast()));
entity.setCurrencyJson(objectMapper.writeValueAsString(it.currencyInfo()));
repository.save(entity);
} catch (Exception e) {
log.error("Failed to persist itinerary {}: {}", it.id(), e.getMessage());
toItinerary method · java · L348-L368 (21 LOC)src/main/java/com/matoe/service/TravelService.java
private UnforgettableItinerary toItinerary(ItineraryEntity e) {
try {
Map<String, Object> insights = parseJson(e.getRegionInsightsJson(), new TypeReference<>() {}, Map.of());
List<AccommodationOption> accomms = parseJson(e.getAccommodationsJson(), new TypeReference<>() {}, List.of());
List<TransportOption> transport = parseJson(e.getTransportJson(), new TypeReference<>() {}, List.of());
List<AttractionOption> attractions = parseJson(e.getAttractionsJson(), new TypeReference<>() {}, List.of());
List<ItineraryVariant> variants = parseJson(e.getVariantsJson(), new TypeReference<>() {}, List.of());
Map<String, Object> weather = parseJson(e.getWeatherJson(), new TypeReference<>() {}, Map.of());
Map<String, Object> currency = parseJson(e.getCurrencyJson(), new TypeReference<>() {}, Map.of());
return new UnforgettableItinerary(e.getId(), e.getDestination(),
e.getStartDaparseJson method · java · L370-L374 (5 LOC)src/main/java/com/matoe/service/TravelService.java
private <T> T parseJson(String json, TypeReference<T> type, T fallback) {
if (json == null || json.isBlank()) return fallback;
try { return objectMapper.readValue(json, type); }
catch (Exception e) { return fallback; }
}‹ prevpage 6 / 6