pddl-planning-service-client
Version:
PDDL Planning Service clients
82 lines • 3.25 kB
JavaScript
/* --------------------------------------------------------------------------------------------
* Copyright (c) Jan Dolejsi. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlannerSyncService = void 0;
const PlannerService_1 = require("./PlannerService");
/** Wraps the `/solve` planning web service interface. */
class PlannerSyncService extends PlannerService_1.PlannerService {
constructor(plannerUrl, plannerConfiguration, providerConfiguration) {
super(plannerUrl, plannerConfiguration, providerConfiguration);
}
createUrl() {
let url = this.plannerPath;
if (this.plannerConfiguration.options) {
url = `${url}?${this.plannerConfiguration.options}`;
}
return url;
}
getTimeout() {
return 60;
}
createRequestBody(domainFileInfo, problemFileInfo) {
const body = {
domain: domainFileInfo.getText(),
problem: problemFileInfo.getText()
};
return Promise.resolve(body);
}
async processServerResponseBody(_origUrl, responseBody, planParser, callbacks) {
const status = responseBody.status;
const result = responseBody.result;
if (result) {
!isEmpty(result.output) && callbacks.handleOutput(result.output + '\n');
result.stdout && callbacks.handleOutput(result.stdout + '\n');
result.stderr && callbacks.handleOutput("Error: " + result.stderr + '\n');
}
if (status === "error") {
if (result) {
const resultOutput = result.output;
if (!isEmpty(resultOutput)) {
callbacks.handleOutput(resultOutput);
}
const resultError = result.error;
if (resultError) {
callbacks.handleOutput(resultError);
}
return [];
}
else {
throw new Error("An error occurred while solving the planning problem: " + JSON.stringify(result));
}
}
else if (status === "ok" && result) {
const resultOutput = result.output;
if (!isEmpty(resultOutput)) {
callbacks.handleOutput(resultOutput + '\n');
}
if (result.plan) {
this.convertPlanSteps(result.plan, planParser);
}
const plans = planParser.getPlans();
if (plans.length > 0) {
callbacks.handlePlan(plans[0]);
}
else {
callbacks.handleOutput('No plan found.\n');
}
return plans;
}
else {
throw new Error(`Planner service failed with status ${status}.`);
}
}
}
exports.PlannerSyncService = PlannerSyncService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function isEmpty(obj) {
return !obj || Object.keys(obj).length === 0;
}
//# sourceMappingURL=PlannerSyncService.js.map