@autonoma-ai/server-node 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,16 @@
1
+ import { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { HandlerConfig } from '@autonoma-ai/sdk';
3
+
4
+ /**
5
+ * Create a Node.js http handler.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { createNodeHandler } from '@autonoma-ai/server-node'
10
+ * import http from 'node:http'
11
+ * http.createServer(createNodeHandler(config)).listen(3000)
12
+ * ```
13
+ */
14
+ declare function createNodeHandler(config: HandlerConfig): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
15
+
16
+ export { createNodeHandler };
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ // src/index.ts
2
+ import { handleRequest } from "@autonoma-ai/sdk";
3
+ function createNodeHandler(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] = val;
9
+ else if (Array.isArray(val)) headers[key] = val[0] ?? "";
10
+ }
11
+ const handlerReq = { body, headers };
12
+ const result = await handleRequest(config, handlerReq);
13
+ res.writeHead(result.status, { "Content-Type": "application/json" });
14
+ res.end(JSON.stringify(result.body));
15
+ };
16
+ }
17
+ function readBody(req) {
18
+ return new Promise((resolve, reject) => {
19
+ const chunks = [];
20
+ req.on("data", (chunk) => chunks.push(chunk));
21
+ req.on("end", () => resolve(Buffer.concat(chunks).toString()));
22
+ req.on("error", reject);
23
+ });
24
+ }
25
+ export {
26
+ createNodeHandler
27
+ };
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from 'node:http'\nimport { handleRequest } from '@autonoma-ai/sdk'\nimport type { HandlerConfig, HandlerRequest } from '@autonoma-ai/sdk'\n\n/**\n * Create a Node.js http handler.\n *\n * @example\n * ```ts\n * import { createNodeHandler } from '@autonoma-ai/server-node'\n * import http from 'node:http'\n * http.createServer(createNodeHandler(config)).listen(3000)\n * ```\n */\nexport function createNodeHandler(config: HandlerConfig) {\n return async (req: IncomingMessage, res: ServerResponse): 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] = val\n else if (Array.isArray(val)) headers[key] = val[0] ?? ''\n }\n\n const handlerReq: HandlerRequest = { body, headers }\n const result = await handleRequest(config, handlerReq)\n\n res.writeHead(result.status, { 'Content-Type': 'application/json' })\n res.end(JSON.stringify(result.body))\n }\n}\n\nfunction readBody(req: IncomingMessage): Promise<string> {\n return new Promise((resolve, reject) => {\n const chunks: Buffer[] = []\n req.on('data', (chunk: Buffer) => chunks.push(chunk))\n req.on('end', () => resolve(Buffer.concat(chunks).toString()))\n req.on('error', reject)\n })\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAavB,SAAS,kBAAkB,QAAuB;AACvD,SAAO,OAAO,KAAsB,QAAuC;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,GAAG,IAAI;AAAA,eACnC,MAAM,QAAQ,GAAG,EAAG,SAAQ,GAAG,IAAI,IAAI,CAAC,KAAK;AAAA,IACxD;AAEA,UAAM,aAA6B,EAAE,MAAM,QAAQ;AACnD,UAAM,SAAS,MAAM,cAAc,QAAQ,UAAU;AAErD,QAAI,UAAU,OAAO,QAAQ,EAAE,gBAAgB,mBAAmB,CAAC;AACnE,QAAI,IAAI,KAAK,UAAU,OAAO,IAAI,CAAC;AAAA,EACrC;AACF;AAEA,SAAS,SAAS,KAAuC;AACvD,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAmB,CAAC;AAC1B,QAAI,GAAG,QAAQ,CAAC,UAAkB,OAAO,KAAK,KAAK,CAAC;AACpD,QAAI,GAAG,OAAO,MAAM,QAAQ,OAAO,OAAO,MAAM,EAAE,SAAS,CAAC,CAAC;AAC7D,QAAI,GAAG,SAAS,MAAM;AAAA,EACxB,CAAC;AACH;","names":[]}
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@autonoma-ai/server-node",
3
+ "version": "0.1.0",
4
+ "description": "Node.js http 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
+ }