@autonoma-ai/server-express 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ import { HandlerConfig } from '@autonoma-ai/sdk';
2
+
3
+ interface ExpressRequest {
4
+ body?: unknown;
5
+ headers: Record<string, string | string[] | undefined>;
6
+ on(event: string, listener: (...args: unknown[]) => void): void;
7
+ }
8
+ interface ExpressResponse {
9
+ status(code: number): ExpressResponse;
10
+ json(body: unknown): void;
11
+ }
12
+ /**
13
+ * Create an Express-compatible handler.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { createExpressHandler } from '@autonoma-ai/server-express'
18
+ * app.post('/api/autonoma', createExpressHandler(config))
19
+ * ```
20
+ */
21
+ declare function createExpressHandler(config: HandlerConfig): (req: ExpressRequest, res: ExpressResponse) => Promise<void>;
22
+
23
+ export { createExpressHandler };
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ // src/index.ts
2
+ import { handleRequest } from "@autonoma-ai/sdk";
3
+ function createExpressHandler(config) {
4
+ return async (req, res) => {
5
+ const body = await readBody(req);
6
+ const headers = {};
7
+ for (const [key, val] of Object.entries(req.headers)) {
8
+ if (typeof val === "string") headers[key.toLowerCase()] = val;
9
+ else if (Array.isArray(val)) headers[key.toLowerCase()] = val[0] ?? "";
10
+ }
11
+ const handlerReq = { body, headers };
12
+ const result = await handleRequest(config, handlerReq);
13
+ res.status(result.status).json(result.body);
14
+ };
15
+ }
16
+ function readBody(req) {
17
+ if (req.body !== void 0 && req.body !== null) {
18
+ return Promise.resolve(
19
+ typeof req.body === "string" ? req.body : JSON.stringify(req.body)
20
+ );
21
+ }
22
+ return new Promise((resolve, reject) => {
23
+ const chunks = [];
24
+ req.on("data", (...args) => chunks.push(args[0]));
25
+ req.on("end", () => resolve(Buffer.concat(chunks).toString()));
26
+ req.on("error", (...args) => reject(args[0]));
27
+ });
28
+ }
29
+ export {
30
+ createExpressHandler
31
+ };
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { handleRequest } from '@autonoma-ai/sdk'\nimport type { HandlerConfig, HandlerRequest } from '@autonoma-ai/sdk'\n\ninterface ExpressRequest {\n body?: unknown\n headers: Record<string, string | string[] | undefined>\n on(event: string, listener: (...args: unknown[]) => void): void\n}\n\ninterface ExpressResponse {\n status(code: number): ExpressResponse\n json(body: unknown): void\n}\n\n/**\n * Create an Express-compatible handler.\n *\n * @example\n * ```ts\n * import { createExpressHandler } from '@autonoma-ai/server-express'\n * app.post('/api/autonoma', createExpressHandler(config))\n * ```\n */\nexport function createExpressHandler(config: HandlerConfig) {\n return async (req: ExpressRequest, res: ExpressResponse): Promise<void> => {\n const body = await readBody(req)\n const headers: Record<string, string> = {}\n for (const [key, val] of Object.entries(req.headers)) {\n if (typeof val === 'string') headers[key.toLowerCase()] = val\n else if (Array.isArray(val)) headers[key.toLowerCase()] = val[0] ?? ''\n }\n\n const handlerReq: HandlerRequest = { body, headers }\n const result = await handleRequest(config, handlerReq)\n res.status(result.status).json(result.body)\n }\n}\n\nfunction readBody(req: ExpressRequest): Promise<string> {\n if (req.body !== undefined && req.body !== null) {\n return Promise.resolve(\n typeof req.body === 'string' ? req.body : JSON.stringify(req.body),\n )\n }\n\n return new Promise((resolve, reject) => {\n const chunks: unknown[] = []\n req.on('data', (...args: unknown[]) => chunks.push(args[0]))\n req.on('end', () => resolve(Buffer.concat(chunks as Uint8Array[]).toString()))\n req.on('error', (...args: unknown[]) => reject(args[0]))\n })\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAuBvB,SAAS,qBAAqB,QAAuB;AAC1D,SAAO,OAAO,KAAqB,QAAwC;AACzE,UAAM,OAAO,MAAM,SAAS,GAAG;AAC/B,UAAM,UAAkC,CAAC;AACzC,eAAW,CAAC,KAAK,GAAG,KAAK,OAAO,QAAQ,IAAI,OAAO,GAAG;AACpD,UAAI,OAAO,QAAQ,SAAU,SAAQ,IAAI,YAAY,CAAC,IAAI;AAAA,eACjD,MAAM,QAAQ,GAAG,EAAG,SAAQ,IAAI,YAAY,CAAC,IAAI,IAAI,CAAC,KAAK;AAAA,IACtE;AAEA,UAAM,aAA6B,EAAE,MAAM,QAAQ;AACnD,UAAM,SAAS,MAAM,cAAc,QAAQ,UAAU;AACrD,QAAI,OAAO,OAAO,MAAM,EAAE,KAAK,OAAO,IAAI;AAAA,EAC5C;AACF;AAEA,SAAS,SAAS,KAAsC;AACtD,MAAI,IAAI,SAAS,UAAa,IAAI,SAAS,MAAM;AAC/C,WAAO,QAAQ;AAAA,MACb,OAAO,IAAI,SAAS,WAAW,IAAI,OAAO,KAAK,UAAU,IAAI,IAAI;AAAA,IACnE;AAAA,EACF;AAEA,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAoB,CAAC;AAC3B,QAAI,GAAG,QAAQ,IAAI,SAAoB,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC;AAC3D,QAAI,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,MAAsB,EAAE,SAAS,CAAC,CAAC;AAC7E,QAAI,GAAG,SAAS,IAAI,SAAoB,OAAO,KAAK,CAAC,CAAC,CAAC;AAAA,EACzD,CAAC;AACH;","names":[]}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@autonoma-ai/server-express",
3
+ "version": "0.1.0",
4
+ "description": "Express/Fastify server adapter for Autonoma SDK",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "import": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "dependencies": {
19
+ "@autonoma-ai/sdk": "0.1.0"
20
+ },
21
+ "devDependencies": {
22
+ "@types/node": "^22.0.0",
23
+ "typescript": "^5.7.0",
24
+ "vitest": "^3.0.0",
25
+ "tsup": "^8.4.0"
26
+ },
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "test": "vitest run --passWithNoTests",
30
+ "clean": "rm -rf dist"
31
+ }
32
+ }