@better-agent/adapters 0.1.0-canary.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.
- package/README.md +3 -0
- package/dist/express.d.mts +9 -0
- package/dist/express.d.mts.map +1 -0
- package/dist/express.mjs +27 -0
- package/dist/express.mjs.map +1 -0
- package/dist/fastify.d.mts +9 -0
- package/dist/fastify.d.mts.map +1 -0
- package/dist/fastify.mjs +21 -0
- package/dist/fastify.mjs.map +1 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +4 -0
- package/dist/shared/disconnect.mjs +21 -0
- package/dist/shared/disconnect.mjs.map +1 -0
- package/dist/shared/from-node-response.mjs +38 -0
- package/dist/shared/from-node-response.mjs.map +1 -0
- package/dist/shared/to-node-request.mjs +40 -0
- package/dist/shared/to-node-request.mjs.map +1 -0
- package/dist/shared/types.d.mts +25 -0
- package/dist/shared/types.d.mts.map +1 -0
- package/package.json +65 -0
package/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { NodeRequestAdapterOptions, NodeRequestLike, NodeResponseLike } from "./shared/types.mjs";
|
|
2
|
+
import { BetterAgentApp } from "@better-agent/core";
|
|
3
|
+
|
|
4
|
+
//#region src/express.d.ts
|
|
5
|
+
type ExpressHandler = (request: NodeRequestLike, response: NodeResponseLike, next?: (error?: unknown) => void) => Promise<void>;
|
|
6
|
+
declare const toExpressHandler: (app: BetterAgentApp, options?: NodeRequestAdapterOptions) => ExpressHandler;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { ExpressHandler, toExpressHandler };
|
|
9
|
+
//# sourceMappingURL=express.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.d.mts","names":[],"sources":["../src/express.ts"],"mappings":";;;;KAOY,cAAA,IACR,OAAA,EAAS,eAAA,EACT,QAAA,EAAU,gBAAA,EACV,IAAA,IAAQ,KAAA,wBACP,OAAA;AAAA,cAEQ,gBAAA,GAAgB,GAAA,EACpB,cAAA,EAAc,OAAA,GACT,yBAAA,KACX,cAAA"}
|
package/dist/express.mjs
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { sendNodeResponse } from "./shared/from-node-response.mjs";
|
|
2
|
+
import { createNodeRequest } from "./shared/to-node-request.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/express.ts
|
|
5
|
+
const toExpressHandler = (app, options) => {
|
|
6
|
+
return async (request, response, next) => {
|
|
7
|
+
try {
|
|
8
|
+
const expressRequest = request;
|
|
9
|
+
const body = expressRequest.body === void 0 || expressRequest.body === null ? void 0 : typeof expressRequest.body === "string" || expressRequest.body instanceof Uint8Array ? expressRequest.body : JSON.stringify(expressRequest.body);
|
|
10
|
+
const webRequest = createNodeRequest(request, response, {
|
|
11
|
+
...options,
|
|
12
|
+
body: options?.body ?? body
|
|
13
|
+
});
|
|
14
|
+
await sendNodeResponse(response, await app.handler(webRequest));
|
|
15
|
+
} catch (error) {
|
|
16
|
+
if (next) {
|
|
17
|
+
next(error);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
export { toExpressHandler };
|
|
27
|
+
//# sourceMappingURL=express.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.mjs","names":[],"sources":["../src/express.ts"],"sourcesContent":["import type { BetterAgentApp } from \"@better-agent/core\";\nimport { sendNodeResponse } from \"./shared/from-node-response\";\nimport { createNodeRequest } from \"./shared/to-node-request\";\nimport type { NodeRequestAdapterOptions, NodeRequestLike, NodeResponseLike } from \"./shared/types\";\n\ntype ExpressRequestLike = NodeRequestLike & { body?: unknown };\n\nexport type ExpressHandler = (\n request: NodeRequestLike,\n response: NodeResponseLike,\n next?: (error?: unknown) => void,\n) => Promise<void>;\n\nexport const toExpressHandler = (\n app: BetterAgentApp,\n options?: NodeRequestAdapterOptions,\n): ExpressHandler => {\n return async (request, response, next) => {\n try {\n const expressRequest = request as ExpressRequestLike;\n const body =\n expressRequest.body === undefined || expressRequest.body === null\n ? undefined\n : typeof expressRequest.body === \"string\" ||\n expressRequest.body instanceof Uint8Array\n ? expressRequest.body\n : JSON.stringify(expressRequest.body);\n\n const webRequest = createNodeRequest(request, response, {\n ...options,\n body: options?.body ?? body,\n });\n const webResponse = await app.handler(webRequest);\n await sendNodeResponse(response, webResponse);\n } catch (error) {\n if (next) {\n next(error);\n return;\n }\n\n throw error;\n }\n };\n};\n"],"mappings":";;;;AAaA,MAAa,oBACT,KACA,YACiB;AACjB,QAAO,OAAO,SAAS,UAAU,SAAS;AACtC,MAAI;GACA,MAAM,iBAAiB;GACvB,MAAM,OACF,eAAe,SAAS,UAAa,eAAe,SAAS,OACvD,SACA,OAAO,eAAe,SAAS,YAC7B,eAAe,gBAAgB,aAC/B,eAAe,OACf,KAAK,UAAU,eAAe,KAAK;GAE/C,MAAM,aAAa,kBAAkB,SAAS,UAAU;IACpD,GAAG;IACH,MAAM,SAAS,QAAQ;IAC1B,CAAC;AAEF,SAAM,iBAAiB,UADH,MAAM,IAAI,QAAQ,WAAW,CACJ;WACxC,OAAO;AACZ,OAAI,MAAM;AACN,SAAK,MAAM;AACX;;AAGJ,SAAM"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FastifyLikeReply, FastifyLikeRequest, NodeRequestAdapterOptions } from "./shared/types.mjs";
|
|
2
|
+
import { BetterAgentApp } from "@better-agent/core";
|
|
3
|
+
|
|
4
|
+
//#region src/fastify.d.ts
|
|
5
|
+
type FastifyHandler = (request: FastifyLikeRequest, reply: FastifyLikeReply) => Promise<void>;
|
|
6
|
+
declare const toFastifyHandler: (app: BetterAgentApp, options?: NodeRequestAdapterOptions) => FastifyHandler;
|
|
7
|
+
//#endregion
|
|
8
|
+
export { FastifyHandler, toFastifyHandler };
|
|
9
|
+
//# sourceMappingURL=fastify.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.d.mts","names":[],"sources":["../src/fastify.ts"],"mappings":";;;;KASY,cAAA,IACR,OAAA,EAAS,kBAAA,EACT,KAAA,EAAO,gBAAA,KACN,OAAA;AAAA,cAEQ,gBAAA,GAAgB,GAAA,EACpB,cAAA,EAAc,OAAA,GACT,yBAAA,KACX,cAAA"}
|
package/dist/fastify.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { sendNodeResponse } from "./shared/from-node-response.mjs";
|
|
2
|
+
import { createNodeRequest } from "./shared/to-node-request.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/fastify.ts
|
|
5
|
+
const toFastifyHandler = (app, options) => {
|
|
6
|
+
return async (request, reply) => {
|
|
7
|
+
reply.hijack?.();
|
|
8
|
+
const body = request.body === void 0 || request.body === null ? void 0 : typeof request.body === "string" || request.body instanceof Uint8Array ? request.body : JSON.stringify(request.body);
|
|
9
|
+
const webRequest = createNodeRequest(request.raw, reply.raw, {
|
|
10
|
+
...options,
|
|
11
|
+
body,
|
|
12
|
+
origin: options?.origin ?? (request.protocol ? `${request.protocol}://${request.raw.headers.host ?? "localhost"}` : void 0)
|
|
13
|
+
});
|
|
14
|
+
const webResponse = await app.handler(webRequest);
|
|
15
|
+
await sendNodeResponse(reply.raw, webResponse);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { toFastifyHandler };
|
|
21
|
+
//# sourceMappingURL=fastify.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fastify.mjs","names":[],"sources":["../src/fastify.ts"],"sourcesContent":["import type { BetterAgentApp } from \"@better-agent/core\";\nimport { sendNodeResponse } from \"./shared/from-node-response\";\nimport { createNodeRequest } from \"./shared/to-node-request\";\nimport type {\n FastifyLikeReply,\n FastifyLikeRequest,\n NodeRequestAdapterOptions,\n} from \"./shared/types\";\n\nexport type FastifyHandler = (\n request: FastifyLikeRequest,\n reply: FastifyLikeReply,\n) => Promise<void>;\n\nexport const toFastifyHandler = (\n app: BetterAgentApp,\n options?: NodeRequestAdapterOptions,\n): FastifyHandler => {\n return async (request, reply) => {\n reply.hijack?.();\n\n const body =\n request.body === undefined || request.body === null\n ? undefined\n : typeof request.body === \"string\" || request.body instanceof Uint8Array\n ? request.body\n : JSON.stringify(request.body);\n\n const webRequest = createNodeRequest(request.raw, reply.raw, {\n ...options,\n body,\n origin:\n options?.origin ??\n (request.protocol\n ? `${request.protocol}://${request.raw.headers.host ?? \"localhost\"}`\n : undefined),\n });\n const webResponse = await app.handler(webRequest);\n await sendNodeResponse(reply.raw, webResponse);\n };\n};\n"],"mappings":";;;;AAcA,MAAa,oBACT,KACA,YACiB;AACjB,QAAO,OAAO,SAAS,UAAU;AAC7B,QAAM,UAAU;EAEhB,MAAM,OACF,QAAQ,SAAS,UAAa,QAAQ,SAAS,OACzC,SACA,OAAO,QAAQ,SAAS,YAAY,QAAQ,gBAAgB,aAC1D,QAAQ,OACR,KAAK,UAAU,QAAQ,KAAK;EAExC,MAAM,aAAa,kBAAkB,QAAQ,KAAK,MAAM,KAAK;GACzD,GAAG;GACH;GACA,QACI,SAAS,WACR,QAAQ,WACH,GAAG,QAAQ,SAAS,KAAK,QAAQ,IAAI,QAAQ,QAAQ,gBACrD;GACb,CAAC;EACF,MAAM,cAAc,MAAM,IAAI,QAAQ,WAAW;AACjD,QAAM,iBAAiB,MAAM,KAAK,YAAY"}
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//#region src/shared/disconnect.ts
|
|
2
|
+
const createDisconnectSignal = (request, response) => {
|
|
3
|
+
const controller = new AbortController();
|
|
4
|
+
const abort = () => {
|
|
5
|
+
if (!controller.signal.aborted) controller.abort();
|
|
6
|
+
};
|
|
7
|
+
if (request.aborted) abort();
|
|
8
|
+
else request.once("aborted", abort);
|
|
9
|
+
response?.once("close", () => {
|
|
10
|
+
if (!response.writableEnded) abort();
|
|
11
|
+
});
|
|
12
|
+
return controller.signal;
|
|
13
|
+
};
|
|
14
|
+
const isDisconnectError = (error) => {
|
|
15
|
+
if (!(error instanceof Error)) return false;
|
|
16
|
+
return error.name === "AbortError" || error.message.includes("aborted");
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { createDisconnectSignal, isDisconnectError };
|
|
21
|
+
//# sourceMappingURL=disconnect.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disconnect.mjs","names":[],"sources":["../../src/shared/disconnect.ts"],"sourcesContent":["export const createDisconnectSignal = (\n request: {\n once(event: \"aborted\", listener: () => void): unknown;\n aborted?: boolean;\n },\n response?: { once(event: \"close\", listener: () => void): unknown; writableEnded?: boolean },\n): AbortSignal => {\n const controller = new AbortController();\n\n const abort = () => {\n if (!controller.signal.aborted) {\n controller.abort();\n }\n };\n\n if (request.aborted) {\n abort();\n } else {\n request.once(\"aborted\", abort);\n }\n response?.once(\"close\", () => {\n if (!response.writableEnded) {\n abort();\n }\n });\n\n return controller.signal;\n};\n\nexport const isDisconnectError = (error: unknown): boolean => {\n if (!(error instanceof Error)) {\n return false;\n }\n\n return error.name === \"AbortError\" || error.message.includes(\"aborted\");\n};\n"],"mappings":";AAAA,MAAa,0BACT,SAIA,aACc;CACd,MAAM,aAAa,IAAI,iBAAiB;CAExC,MAAM,cAAc;AAChB,MAAI,CAAC,WAAW,OAAO,QACnB,YAAW,OAAO;;AAI1B,KAAI,QAAQ,QACR,QAAO;KAEP,SAAQ,KAAK,WAAW,MAAM;AAElC,WAAU,KAAK,eAAe;AAC1B,MAAI,CAAC,SAAS,cACV,QAAO;GAEb;AAEF,QAAO,WAAW;;AAGtB,MAAa,qBAAqB,UAA4B;AAC1D,KAAI,EAAE,iBAAiB,OACnB,QAAO;AAGX,QAAO,MAAM,SAAS,gBAAgB,MAAM,QAAQ,SAAS,UAAU"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isDisconnectError } from "./disconnect.mjs";
|
|
2
|
+
import { once } from "node:events";
|
|
3
|
+
import { Readable } from "node:stream";
|
|
4
|
+
|
|
5
|
+
//#region src/shared/from-node-response.ts
|
|
6
|
+
const waitForDrain = async (response) => {
|
|
7
|
+
await once(response, "drain");
|
|
8
|
+
};
|
|
9
|
+
const setResponseHeaders = (target, source) => {
|
|
10
|
+
const getSetCookie = source.getSetCookie;
|
|
11
|
+
if (typeof getSetCookie === "function") {
|
|
12
|
+
const cookies = getSetCookie.call(source);
|
|
13
|
+
if (cookies.length > 0) target.setHeader("set-cookie", cookies);
|
|
14
|
+
}
|
|
15
|
+
source.forEach((value, name) => {
|
|
16
|
+
if (name === "set-cookie" && target.hasHeader("set-cookie")) return;
|
|
17
|
+
target.setHeader(name, value);
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const sendNodeResponse = async (target, response) => {
|
|
21
|
+
target.statusCode = response.status;
|
|
22
|
+
setResponseHeaders(target, response.headers);
|
|
23
|
+
if (!response.body) {
|
|
24
|
+
target.end();
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const body = Readable.fromWeb(response.body);
|
|
28
|
+
try {
|
|
29
|
+
for await (const chunk of body) if (!target.write(chunk)) await waitForDrain(target);
|
|
30
|
+
target.end();
|
|
31
|
+
} catch (error) {
|
|
32
|
+
if (!isDisconnectError(error) && !target.destroyed) throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { sendNodeResponse };
|
|
38
|
+
//# sourceMappingURL=from-node-response.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"from-node-response.mjs","names":[],"sources":["../../src/shared/from-node-response.ts"],"sourcesContent":["import { once } from \"node:events\";\nimport { Readable } from \"node:stream\";\nimport { isDisconnectError } from \"./disconnect\";\nimport type { NodeResponseLike } from \"./types\";\n\nconst waitForDrain = async (response: NodeResponseLike) => {\n await once(response, \"drain\");\n};\n\nconst setResponseHeaders = (target: NodeResponseLike, source: Headers) => {\n const getSetCookie = (\n source as Headers & {\n getSetCookie?: () => string[];\n }\n ).getSetCookie;\n\n if (typeof getSetCookie === \"function\") {\n const cookies = getSetCookie.call(source);\n if (cookies.length > 0) {\n target.setHeader(\"set-cookie\", cookies);\n }\n }\n\n source.forEach((value, name) => {\n if (name === \"set-cookie\" && target.hasHeader(\"set-cookie\")) {\n return;\n }\n\n target.setHeader(name, value);\n });\n};\n\nexport const sendNodeResponse = async (\n target: NodeResponseLike,\n response: Response,\n): Promise<void> => {\n target.statusCode = response.status;\n setResponseHeaders(target, response.headers);\n\n if (!response.body) {\n target.end();\n return;\n }\n\n const body = Readable.fromWeb(response.body as never);\n\n try {\n for await (const chunk of body) {\n if (!target.write(chunk)) {\n await waitForDrain(target);\n }\n }\n target.end();\n } catch (error) {\n if (!isDisconnectError(error) && !target.destroyed) {\n throw error;\n }\n }\n};\n"],"mappings":";;;;;AAKA,MAAM,eAAe,OAAO,aAA+B;AACvD,OAAM,KAAK,UAAU,QAAQ;;AAGjC,MAAM,sBAAsB,QAA0B,WAAoB;CACtE,MAAM,eACF,OAGF;AAEF,KAAI,OAAO,iBAAiB,YAAY;EACpC,MAAM,UAAU,aAAa,KAAK,OAAO;AACzC,MAAI,QAAQ,SAAS,EACjB,QAAO,UAAU,cAAc,QAAQ;;AAI/C,QAAO,SAAS,OAAO,SAAS;AAC5B,MAAI,SAAS,gBAAgB,OAAO,UAAU,aAAa,CACvD;AAGJ,SAAO,UAAU,MAAM,MAAM;GAC/B;;AAGN,MAAa,mBAAmB,OAC5B,QACA,aACgB;AAChB,QAAO,aAAa,SAAS;AAC7B,oBAAmB,QAAQ,SAAS,QAAQ;AAE5C,KAAI,CAAC,SAAS,MAAM;AAChB,SAAO,KAAK;AACZ;;CAGJ,MAAM,OAAO,SAAS,QAAQ,SAAS,KAAc;AAErD,KAAI;AACA,aAAW,MAAM,SAAS,KACtB,KAAI,CAAC,OAAO,MAAM,MAAM,CACpB,OAAM,aAAa,OAAO;AAGlC,SAAO,KAAK;UACP,OAAO;AACZ,MAAI,CAAC,kBAAkB,MAAM,IAAI,CAAC,OAAO,UACrC,OAAM"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createDisconnectSignal } from "./disconnect.mjs";
|
|
2
|
+
import { Readable } from "node:stream";
|
|
3
|
+
|
|
4
|
+
//#region src/shared/to-node-request.ts
|
|
5
|
+
const bodylessMethods = new Set(["GET", "HEAD"]);
|
|
6
|
+
const resolveHeader = (value) => {
|
|
7
|
+
if (Array.isArray(value)) return value.join(", ");
|
|
8
|
+
return typeof value === "string" ? value : null;
|
|
9
|
+
};
|
|
10
|
+
const resolveOrigin = (request, options) => {
|
|
11
|
+
if (options?.origin) return options.origin;
|
|
12
|
+
return `${resolveHeader(request.headers["x-forwarded-proto"]) ?? request.protocol ?? "http"}://${resolveHeader(request.headers.host) ?? "localhost"}`;
|
|
13
|
+
};
|
|
14
|
+
const createNodeRequest = (request, response, options) => {
|
|
15
|
+
const method = request.method ?? "GET";
|
|
16
|
+
const url = options?.url ?? request.originalUrl ?? request.url ?? "/";
|
|
17
|
+
const signal = createDisconnectSignal(request, response);
|
|
18
|
+
const headers = new Headers();
|
|
19
|
+
for (const [name, value] of Object.entries(request.headers)) {
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
for (const item of value) headers.append(name, item);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === "string") headers.set(name, value);
|
|
25
|
+
}
|
|
26
|
+
const requestInit = {
|
|
27
|
+
method,
|
|
28
|
+
headers,
|
|
29
|
+
signal
|
|
30
|
+
};
|
|
31
|
+
if (!bodylessMethods.has(method.toUpperCase())) {
|
|
32
|
+
requestInit.body = options?.body ?? Readable.toWeb(request);
|
|
33
|
+
requestInit.duplex = "half";
|
|
34
|
+
}
|
|
35
|
+
return new Request(new URL(url, resolveOrigin(request, options)), requestInit);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createNodeRequest };
|
|
40
|
+
//# sourceMappingURL=to-node-request.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-node-request.mjs","names":[],"sources":["../../src/shared/to-node-request.ts"],"sourcesContent":["import { Readable } from \"node:stream\";\nimport { createDisconnectSignal } from \"./disconnect\";\nimport type { NodeRequestAdapterOptions, NodeRequestLike } from \"./types\";\n\nconst bodylessMethods = new Set([\"GET\", \"HEAD\"]);\n\nconst resolveHeader = (value: string | string[] | undefined): string | null => {\n if (Array.isArray(value)) {\n return value.join(\", \");\n }\n\n return typeof value === \"string\" ? value : null;\n};\n\nconst resolveOrigin = (request: NodeRequestLike, options?: NodeRequestAdapterOptions): string => {\n if (options?.origin) {\n return options.origin;\n }\n\n const forwardedProto = resolveHeader(request.headers[\"x-forwarded-proto\"]);\n const protocol = forwardedProto ?? request.protocol ?? \"http\";\n const host = resolveHeader(request.headers.host) ?? \"localhost\";\n return `${protocol}://${host}`;\n};\n\nexport const createNodeRequest = (\n request: NodeRequestLike,\n response?: { once(event: \"close\", listener: () => void): unknown; writableEnded?: boolean },\n options?: NodeRequestAdapterOptions,\n): Request => {\n const method = request.method ?? \"GET\";\n const url = options?.url ?? request.originalUrl ?? request.url ?? \"/\";\n const signal = createDisconnectSignal(request, response as never);\n\n const headers = new Headers();\n for (const [name, value] of Object.entries(request.headers)) {\n if (Array.isArray(value)) {\n for (const item of value) {\n headers.append(name, item);\n }\n continue;\n }\n\n if (typeof value === \"string\") {\n headers.set(name, value);\n }\n }\n\n const requestInit: RequestInit & { duplex?: \"half\" } = {\n method,\n headers,\n signal,\n };\n\n if (!bodylessMethods.has(method.toUpperCase())) {\n requestInit.body = options?.body ?? (Readable.toWeb(request) as unknown as BodyInit);\n requestInit.duplex = \"half\";\n }\n\n return new Request(new URL(url, resolveOrigin(request, options)), requestInit);\n};\n"],"mappings":";;;;AAIA,MAAM,kBAAkB,IAAI,IAAI,CAAC,OAAO,OAAO,CAAC;AAEhD,MAAM,iBAAiB,UAAwD;AAC3E,KAAI,MAAM,QAAQ,MAAM,CACpB,QAAO,MAAM,KAAK,KAAK;AAG3B,QAAO,OAAO,UAAU,WAAW,QAAQ;;AAG/C,MAAM,iBAAiB,SAA0B,YAAgD;AAC7F,KAAI,SAAS,OACT,QAAO,QAAQ;AAMnB,QAAO,GAHgB,cAAc,QAAQ,QAAQ,qBAAqB,IACvC,QAAQ,YAAY,OAEpC,KADN,cAAc,QAAQ,QAAQ,KAAK,IAAI;;AAIxD,MAAa,qBACT,SACA,UACA,YACU;CACV,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,MAAM,SAAS,OAAO,QAAQ,eAAe,QAAQ,OAAO;CAClE,MAAM,SAAS,uBAAuB,SAAS,SAAkB;CAEjE,MAAM,UAAU,IAAI,SAAS;AAC7B,MAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,QAAQ,QAAQ,EAAE;AACzD,MAAI,MAAM,QAAQ,MAAM,EAAE;AACtB,QAAK,MAAM,QAAQ,MACf,SAAQ,OAAO,MAAM,KAAK;AAE9B;;AAGJ,MAAI,OAAO,UAAU,SACjB,SAAQ,IAAI,MAAM,MAAM;;CAIhC,MAAM,cAAiD;EACnD;EACA;EACA;EACH;AAED,KAAI,CAAC,gBAAgB,IAAI,OAAO,aAAa,CAAC,EAAE;AAC5C,cAAY,OAAO,SAAS,QAAS,SAAS,MAAM,QAAQ;AAC5D,cAAY,SAAS;;AAGzB,QAAO,IAAI,QAAQ,IAAI,IAAI,KAAK,cAAc,SAAS,QAAQ,CAAC,EAAE,YAAY"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IncomingMessage, ServerResponse } from "node:http";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/types.d.ts
|
|
4
|
+
interface NodeRequestAdapterOptions {
|
|
5
|
+
origin?: string;
|
|
6
|
+
url?: string;
|
|
7
|
+
body?: BodyInit | null;
|
|
8
|
+
}
|
|
9
|
+
type NodeRequestLike = IncomingMessage & {
|
|
10
|
+
originalUrl?: string;
|
|
11
|
+
protocol?: string;
|
|
12
|
+
};
|
|
13
|
+
type NodeResponseLike = ServerResponse<IncomingMessage>;
|
|
14
|
+
interface FastifyLikeRequest {
|
|
15
|
+
body?: unknown;
|
|
16
|
+
raw: NodeRequestLike;
|
|
17
|
+
protocol?: string;
|
|
18
|
+
}
|
|
19
|
+
interface FastifyLikeReply {
|
|
20
|
+
raw: NodeResponseLike;
|
|
21
|
+
hijack?(): void;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { FastifyLikeReply, FastifyLikeRequest, NodeRequestAdapterOptions, NodeRequestLike, NodeResponseLike };
|
|
25
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../../src/shared/types.ts"],"mappings":";;;UAEiB,yBAAA;EACb,MAAA;EACA,GAAA;EACA,IAAA,GAAO,QAAA;AAAA;AAAA,KAGC,eAAA,GAAkB,eAAA;EAC1B,WAAA;EACA,QAAA;AAAA;AAAA,KAGQ,gBAAA,GAAmB,cAAA,CAAe,eAAA;AAAA,UAE7B,kBAAA;EACb,IAAA;EACA,GAAA,EAAK,eAAA;EACL,QAAA;AAAA;AAAA,UAGa,gBAAA;EACb,GAAA,EAAK,gBAAA;EACL,MAAA;AAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@better-agent/adapters",
|
|
3
|
+
"version": "0.1.0-canary.0",
|
|
4
|
+
"description": "Better Agent framework adapters",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/better-agent/better-agent.git",
|
|
9
|
+
"directory": "packages/adapters"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/better-agent/better-agent/tree/main/packages/adapters",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/better-agent/better-agent/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"types": "./dist/index.d.mts",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"import": "./dist/index.mjs"
|
|
22
|
+
},
|
|
23
|
+
"./express": {
|
|
24
|
+
"types": "./dist/express.d.mts",
|
|
25
|
+
"import": "./dist/express.mjs"
|
|
26
|
+
},
|
|
27
|
+
"./fastify": {
|
|
28
|
+
"types": "./dist/fastify.d.mts",
|
|
29
|
+
"import": "./dist/fastify.mjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"typesVersions": {
|
|
33
|
+
"*": {
|
|
34
|
+
".": ["dist/index.d.mts"],
|
|
35
|
+
"express": ["dist/express.d.mts"],
|
|
36
|
+
"fastify": ["dist/fastify.d.mts"]
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "bunx tsdown",
|
|
41
|
+
"dev": "bunx tsdown --watch --no-clean",
|
|
42
|
+
"lint:package": "bunx publint run --strict",
|
|
43
|
+
"lint:types": "npm_config_cache=../../.npm-cache bunx attw --profile esm-only --pack .",
|
|
44
|
+
"lint": "bunx biome check .",
|
|
45
|
+
"typecheck": "bunx tsc -p tsconfig.json --noEmit",
|
|
46
|
+
"format": "bunx biome format --write .",
|
|
47
|
+
"clean": "bunx rimraf dist"
|
|
48
|
+
},
|
|
49
|
+
"files": ["dist"],
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@better-agent/core": "0.0.1",
|
|
55
|
+
"@types/bun": "^1.2.18",
|
|
56
|
+
"@types/express": "^5.0.3",
|
|
57
|
+
"@types/node": "^22.15.30",
|
|
58
|
+
"express": "^5.1.0",
|
|
59
|
+
"fastify": "^5.6.1",
|
|
60
|
+
"neverthrow": "^8.2.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@better-agent/core": "0.0.1"
|
|
64
|
+
}
|
|
65
|
+
}
|