@autonoma-ai/server-web 0.1.0 → 0.1.3

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 ADDED
@@ -0,0 +1,83 @@
1
+ # @autonoma-ai/server-web
2
+
3
+ Web standard server adapter for the Autonoma SDK. Works with Next.js App Router, Hono, Bun, and Deno — any framework that uses the standard `Request`/`Response` API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @autonoma-ai/sdk @autonoma-ai/sdk-prisma @autonoma-ai/server-web
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Next.js App Router
14
+
15
+ ```typescript
16
+ // app/api/autonoma/route.ts
17
+ import { createHandler } from '@autonoma-ai/server-web'
18
+ import { prismaAdapter } from '@autonoma-ai/sdk-prisma'
19
+ import { prisma } from '@/lib/db'
20
+
21
+ export const POST = createHandler({
22
+ adapter: prismaAdapter(prisma, { scopeField: 'organizationId' }),
23
+ sharedSecret: process.env.AUTONOMA_SHARED_SECRET!,
24
+ signingSecret: process.env.AUTONOMA_SIGNING_SECRET!,
25
+ auth: async (user) => {
26
+ const session = await createSession(user.id as string)
27
+ return { token: session.token }
28
+ },
29
+ })
30
+ ```
31
+
32
+ ### Hono
33
+
34
+ ```typescript
35
+ import { Hono } from 'hono'
36
+ import { createHandler } from '@autonoma-ai/server-web'
37
+
38
+ const app = new Hono()
39
+ const handler = createHandler(config)
40
+
41
+ app.post('/api/autonoma', (c) => handler(c.req.raw))
42
+ ```
43
+
44
+ ### Bun
45
+
46
+ ```typescript
47
+ import { createHandler } from '@autonoma-ai/server-web'
48
+
49
+ const handler = createHandler(config)
50
+
51
+ Bun.serve({
52
+ fetch(req) {
53
+ if (req.method === 'POST' && new URL(req.url).pathname === '/api/autonoma') {
54
+ return handler(req)
55
+ }
56
+ return new Response('Not found', { status: 404 })
57
+ },
58
+ })
59
+ ```
60
+
61
+ ## Auth callback
62
+
63
+ The `auth` callback receives the first `User` created during setup and must return real credentials that the test runner can use to log in:
64
+
65
+ ```typescript
66
+ // Session cookie
67
+ auth: async (user) => {
68
+ const session = await createSession(user.id as string)
69
+ return {
70
+ cookies: [{ name: 'session', value: session.token, httpOnly: true, sameSite: 'lax', path: '/' }],
71
+ }
72
+ }
73
+
74
+ // Bearer token
75
+ auth: async (user) => {
76
+ const token = jwt.sign({ sub: user.id }, SECRET)
77
+ return { token }
78
+ }
79
+ ```
80
+
81
+ ## Documentation
82
+
83
+ Full docs: [docs/](../../docs/) — see [setup guide](../../docs/setup.txt).
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/index.ts
2
2
  import { handleRequest } from "@autonoma-ai/sdk";
3
3
  function createHandler(config) {
4
+ const enrichedConfig = { ...config, sdk: { ...config.sdk, server: "web" } };
4
5
  return async (req) => {
5
6
  const body = await req.text();
6
7
  const headers = {};
@@ -8,7 +9,7 @@ function createHandler(config) {
8
9
  headers[key.toLowerCase()] = value;
9
10
  });
10
11
  const handlerReq = { body, headers };
11
- const res = await handleRequest(config, handlerReq);
12
+ const res = await handleRequest(enrichedConfig, handlerReq);
12
13
  return new Response(JSON.stringify(res.body), {
13
14
  status: res.status,
14
15
  headers: { "Content-Type": "application/json" }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { handleRequest } from '@autonoma-ai/sdk'\nimport type { HandlerConfig, HandlerRequest } from '@autonoma-ai/sdk'\n\n/**\n * Create a Web standard handler (works with Next App Router, Hono, Bun, Deno).\n *\n * @example\n * ```ts\n * import { createHandler } from '@autonoma-ai/server-web'\n * const handler = createHandler(config)\n * // Next.js App Router:\n * export const POST = handler\n * ```\n */\nexport function createHandler(config: HandlerConfig) {\n return async (req: Request): Promise<Response> => {\n const body = await req.text()\n const headers: Record<string, string> = {}\n req.headers.forEach((value, key) => {\n headers[key.toLowerCase()] = value\n })\n\n const handlerReq: HandlerRequest = { body, headers }\n const res = await handleRequest(config, handlerReq)\n\n return new Response(JSON.stringify(res.body), {\n status: res.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAcvB,SAAS,cAAc,QAAuB;AACnD,SAAO,OAAO,QAAoC;AAChD,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,UAAkC,CAAC;AACzC,QAAI,QAAQ,QAAQ,CAAC,OAAO,QAAQ;AAClC,cAAQ,IAAI,YAAY,CAAC,IAAI;AAAA,IAC/B,CAAC;AAED,UAAM,aAA6B,EAAE,MAAM,QAAQ;AACnD,UAAM,MAAM,MAAM,cAAc,QAAQ,UAAU;AAElD,WAAO,IAAI,SAAS,KAAK,UAAU,IAAI,IAAI,GAAG;AAAA,MAC5C,QAAQ,IAAI;AAAA,MACZ,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAChD,CAAC;AAAA,EACH;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { handleRequest } from '@autonoma-ai/sdk'\nimport type { HandlerConfig, HandlerRequest } from '@autonoma-ai/sdk'\n\n/**\n * Create a Web standard handler (works with Next App Router, Hono, Bun, Deno).\n *\n * @example\n * ```ts\n * import { createHandler } from '@autonoma-ai/server-web'\n * const handler = createHandler(config)\n * // Next.js App Router:\n * export const POST = handler\n * ```\n */\nexport function createHandler(config: HandlerConfig) {\n const enrichedConfig = { ...config, sdk: { ...config.sdk, server: 'web' } }\n return async (req: Request): Promise<Response> => {\n const body = await req.text()\n const headers: Record<string, string> = {}\n req.headers.forEach((value, key) => {\n headers[key.toLowerCase()] = value\n })\n\n const handlerReq: HandlerRequest = { body, headers }\n const res = await handleRequest(enrichedConfig, handlerReq)\n\n return new Response(JSON.stringify(res.body), {\n status: res.status,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n}\n"],"mappings":";AAAA,SAAS,qBAAqB;AAcvB,SAAS,cAAc,QAAuB;AACnD,QAAM,iBAAiB,EAAE,GAAG,QAAQ,KAAK,EAAE,GAAG,OAAO,KAAK,QAAQ,MAAM,EAAE;AAC1E,SAAO,OAAO,QAAoC;AAChD,UAAM,OAAO,MAAM,IAAI,KAAK;AAC5B,UAAM,UAAkC,CAAC;AACzC,QAAI,QAAQ,QAAQ,CAAC,OAAO,QAAQ;AAClC,cAAQ,IAAI,YAAY,CAAC,IAAI;AAAA,IAC/B,CAAC;AAED,UAAM,aAA6B,EAAE,MAAM,QAAQ;AACnD,UAAM,MAAM,MAAM,cAAc,gBAAgB,UAAU;AAE1D,WAAO,IAAI,SAAS,KAAK,UAAU,IAAI,IAAI,GAAG;AAAA,MAC5C,QAAQ,IAAI;AAAA,MACZ,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,IAChD,CAAC;AAAA,EACH;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonoma-ai/server-web",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "Web standard (Hono, Next App Router, Bun, Deno) server adapter for Autonoma SDK",
5
5
  "type": "module",
6
6
  "exports": {
@@ -16,7 +16,7 @@
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@autonoma-ai/sdk": "0.1.0"
19
+ "@autonoma-ai/sdk": "0.1.3"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/node": "^22.0.0",