@looopy-ai/aws 1.0.6 → 2.0.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/dist/agentcore-runtime-server.d.ts +6 -10
- package/dist/agentcore-runtime-server.js +19 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/nodejs.d.ts +2 -0
- package/dist/nodejs.js +9 -0
- package/package.json +1 -1
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { type HttpBindings } from '@hono/node-server';
|
|
2
1
|
import { type Agent, type AuthContext } from '@looopy-ai/core';
|
|
3
2
|
import { Hono } from 'hono';
|
|
4
3
|
import type pino from 'pino';
|
|
5
|
-
type ServeConfig = {
|
|
4
|
+
export type ServeConfig = {
|
|
6
5
|
agent: (contextId: string) => Promise<Agent>;
|
|
7
6
|
decodeAuthorization?: (authorization: string) => Promise<AuthContext | null>;
|
|
7
|
+
logger: pino.Logger;
|
|
8
8
|
port?: number;
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
10
|
+
export type HonoVariables = {
|
|
11
|
+
logger: pino.Logger;
|
|
12
|
+
};
|
|
15
13
|
export declare const hono: (config: ServeConfig) => Hono<{
|
|
16
|
-
|
|
14
|
+
Variables: HonoVariables;
|
|
17
15
|
}>;
|
|
18
|
-
export declare const serve: (config: ServeConfig) => void;
|
|
19
|
-
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { serve as serveNodeJs } from '@hono/node-server';
|
|
2
1
|
import { getLogger, SSEServer } from '@looopy-ai/core';
|
|
3
2
|
import { Hono } from 'hono';
|
|
4
3
|
import { requestId } from 'hono/request-id';
|
|
5
|
-
import { pinoHttp } from 'pino-http';
|
|
6
4
|
import { z } from 'zod';
|
|
7
5
|
const promptValidator = z.object({
|
|
8
6
|
prompt: z.string().min(1),
|
|
@@ -10,11 +8,24 @@ const promptValidator = z.object({
|
|
|
10
8
|
export const hono = (config) => {
|
|
11
9
|
const app = new Hono();
|
|
12
10
|
app.use(requestId());
|
|
13
|
-
app.use(async (c, next) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
app.use('*', async (c, next) => {
|
|
12
|
+
const requestId = c.var.requestId;
|
|
13
|
+
const child = (config.logger.child ?? getLogger)({
|
|
14
|
+
requestId,
|
|
15
|
+
method: c.req.method,
|
|
16
|
+
path: c.req.path,
|
|
17
|
+
});
|
|
18
|
+
const start = performance.now();
|
|
19
|
+
c.set('logger', child);
|
|
20
|
+
try {
|
|
21
|
+
await next();
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
if (c.req.path !== '/ping') {
|
|
25
|
+
const ms = performance.now() - start;
|
|
26
|
+
child.info({ status: c.res.status, ms }, 'request completed');
|
|
27
|
+
}
|
|
28
|
+
}
|
|
18
29
|
});
|
|
19
30
|
const state = { busy: false, agent: undefined };
|
|
20
31
|
app.get('/ping', async (c) => {
|
|
@@ -23,7 +34,7 @@ export const hono = (config) => {
|
|
|
23
34
|
time_of_last_update: Date.now(),
|
|
24
35
|
}));
|
|
25
36
|
});
|
|
26
|
-
app.post('/
|
|
37
|
+
app.post('/invocations', async (c) => {
|
|
27
38
|
const logger = c.var.logger;
|
|
28
39
|
if (state.busy) {
|
|
29
40
|
return c.json({ error: 'Agent is currently busy' }, 503);
|
|
@@ -101,13 +112,6 @@ export const hono = (config) => {
|
|
|
101
112
|
});
|
|
102
113
|
return app;
|
|
103
114
|
};
|
|
104
|
-
export const serve = (config) => {
|
|
105
|
-
const app = hono(config);
|
|
106
|
-
serveNodeJs({
|
|
107
|
-
fetch: app.fetch,
|
|
108
|
-
port: config.port || 8080,
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
115
|
const getAuthContext = async (authorization, decoder) => {
|
|
112
116
|
if (!authorization || !decoder) {
|
|
113
117
|
return null;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/nodejs.d.ts
ADDED
package/dist/nodejs.js
ADDED