pddl-planning-service-client
Version:
PDDL Planning Service clients
68 lines • 3.77 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.instanceOfHttpConnectionRefusedError = exports.instanceOfHttpConnectionError = exports.PlannerService = void 0;
const pddl_workspace_1 = require("pddl-workspace");
const httpUtils_1 = require("./httpUtils");
const url_1 = require("url");
/** Abstract implementation of both sync/async planning service client. */
class PlannerService extends pddl_workspace_1.planner.Planner {
constructor(plannerUrl, plannerConfiguration, providerConfiguration) {
super(plannerUrl, plannerConfiguration, providerConfiguration);
}
async plan(domainFileInfo, problemFileInfo, planParser, parent) {
parent.handleOutput(`Planning service: ${this.plannerPath}\nDomain: ${domainFileInfo.name}, Problem: ${problemFileInfo.name}\n`);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let requestHeader = {};
if (this.plannerConfiguration.authentication?.getToken() !== undefined) {
requestHeader = {
"Authorization": "Bearer " + this.plannerConfiguration.authentication.getToken()
};
}
// currently, this is used to notify any observers that planning is starting
parent.providePlannerOptions({ domain: domainFileInfo, problem: problemFileInfo });
const requestBody = await this.createRequestBody(domainFileInfo, problemFileInfo);
if (!requestBody) {
return [];
}
const url = this.createUrl();
const timeoutInSec = this.getTimeout();
const output = await (0, httpUtils_1.postJson)(new url_1.URL(url), requestBody, {
isAuthenticated: this.plannerConfiguration.authentication !== undefined,
serviceFriendlyName: 'PDDL Planning Service',
headers: requestHeader,
json: true,
timeout: timeoutInSec * 1000 * 1.1,
});
const plans = await this.processServerResponseBody(url, output, planParser, parent);
return plans;
}
convertPlanSteps(planSteps, planParser) {
for (let index = 0; index < planSteps.length; index++) {
const planStep = planSteps[index];
const fullActionName = planStep.name.replace('(', '').replace(')', '');
const time = planStep.time ?? (index + 1) * planParser.options.epsilon;
let duration = planStep.duration;
const isDurative = duration !== undefined && duration !== null;
duration = duration ?? planParser.options.epsilon;
const planStepObj = new pddl_workspace_1.PlanStep(time, fullActionName, isDurative, duration, index);
planParser.appendStep(planStepObj);
}
planParser.onPlanFinished();
}
}
exports.PlannerService = PlannerService;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function instanceOfHttpConnectionError(object) {
return 'address' in object && 'port' in object && 'code' in object && 'message' in object;
}
exports.instanceOfHttpConnectionError = instanceOfHttpConnectionError;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function instanceOfHttpConnectionRefusedError(object) {
return (instanceOfHttpConnectionError(object)) && object.code === 'ECONNREFUSED';
}
exports.instanceOfHttpConnectionRefusedError = instanceOfHttpConnectionRefusedError;
//# sourceMappingURL=PlannerService.js.map