Files
SuperBizAgent-java/src/main/java/com/superbiz/agent/harness/application/ChatApplicationResult.java
T

40 lines
1.7 KiB
Java

package com.superbiz.agent.harness.application;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.superbiz.agent.harness.contract.IntentType;
import com.superbiz.agent.harness.contract.ReleaseOutcome;
import java.util.Objects;
public record ChatApplicationResult(
@JsonProperty("session_id") String sessionId,
@JsonProperty("run_id") String runId,
@JsonProperty("intent") IntentType intent,
@JsonProperty("outcome") ReleaseOutcome outcome,
@JsonProperty("content_type") ChatContentType contentType,
@JsonProperty("content") ChatApplicationContent content) {
public ChatApplicationResult {
requireText(sessionId, "sessionId");
requireText(runId, "runId");
Objects.requireNonNull(intent, "intent must not be null");
Objects.requireNonNull(outcome, "outcome must not be null");
Objects.requireNonNull(content, "content must not be null");
if (outcome != ReleaseOutcome.SUCCESS && outcome != ReleaseOutcome.FALLBACK) {
throw new IllegalArgumentException("application result must be SUCCESS or FALLBACK");
}
if (contentType != content.contentType()) {
throw new IllegalArgumentException("contentType does not match content");
}
if (outcome == ReleaseOutcome.FALLBACK && contentType != ChatContentType.SAFE_FALLBACK) {
throw new IllegalArgumentException("fallback outcome requires safe fallback content");
}
}
private static void requireText(String value, String name) {
if (value == null || value.isBlank()) {
throw new IllegalArgumentException(name + " must not be blank");
}
}
}