@kddd/artinet-sdk
Version:
TypeScript SDK for the Agent2Agent (A2A) Protocol
49 lines • 1.73 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createExpressServer = createExpressServer;
const cors_1 = __importDefault(require("cors"));
const express_1 = __importDefault(require("express"));
/**
* Creates an Express server for the A2A protocol.
* Handles task creation, streaming, cancellation and more.
* Uses Jayson for JSON-RPC handling.
*/
function createExpressServer(params) {
const { card, corsOptions, basePath, rpcServer, fallbackPath, errorHandler, onTaskSendSubscribe, onTaskResubscribe, } = params;
const app = (0, express_1.default)();
app.use((0, cors_1.default)(corsOptions));
app.use(express_1.default.json());
app.get("/.well-known/agent.json", (_, res) => {
res.json(card);
});
app.get(fallbackPath, (_, res) => {
res.json(card);
});
//SSE Paths
app.post(basePath, async (req, res, next) => {
try {
const body = req.body;
if (body && body.method) {
if (body.method === "tasks/sendSubscribe") {
return await onTaskSendSubscribe(body, res);
}
else if (body.method === "tasks/resubscribe") {
return await onTaskResubscribe(body, res);
}
}
next();
}
catch (error) {
next(error);
}
});
//RPC server
app.post(basePath, rpcServer.middleware());
// Fallback error handler
app.use(errorHandler);
return { app };
}
//# sourceMappingURL=express-server.js.map