@rcrsr/rill-agent-http 0.18.5
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/LICENSE +21 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +109 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Andre Bremer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
|
|
5
|
+
export interface HandlerDescription {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly description?: string | undefined;
|
|
8
|
+
readonly params: ReadonlyArray<{
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly type: string;
|
|
11
|
+
readonly required: boolean;
|
|
12
|
+
readonly description?: string | undefined;
|
|
13
|
+
readonly defaultValue?: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
}
|
|
16
|
+
export interface RunRequest {
|
|
17
|
+
readonly params?: Record<string, unknown> | undefined;
|
|
18
|
+
readonly timeout?: number | undefined;
|
|
19
|
+
}
|
|
20
|
+
export interface RunContext {
|
|
21
|
+
readonly sessionVars?: Record<string, string> | undefined;
|
|
22
|
+
readonly onLog?: ((message: string) => void) | undefined;
|
|
23
|
+
readonly onChunk?: ((chunk: unknown) => Promise<void>) | undefined;
|
|
24
|
+
}
|
|
25
|
+
export interface RunResponse {
|
|
26
|
+
readonly state: "completed" | "error";
|
|
27
|
+
readonly result: unknown;
|
|
28
|
+
readonly streamed?: boolean | undefined;
|
|
29
|
+
}
|
|
30
|
+
export interface AgentRouter {
|
|
31
|
+
run(agentName: string, request: RunRequest, context?: RunContext): Promise<RunResponse>;
|
|
32
|
+
describe(agentName: string): HandlerDescription | null;
|
|
33
|
+
agents(): string[];
|
|
34
|
+
defaultAgent(): string;
|
|
35
|
+
dispose(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export interface HttpHarness {
|
|
38
|
+
listen(port?: number): Promise<void>;
|
|
39
|
+
close(): Promise<void>;
|
|
40
|
+
readonly app: Hono;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create an HTTP harness wrapping an AgentRouter.
|
|
44
|
+
*
|
|
45
|
+
* Routes:
|
|
46
|
+
* GET /agents — list agents with descriptions
|
|
47
|
+
* POST /agents/:name/run — execute a named agent
|
|
48
|
+
* POST /run — execute the default agent
|
|
49
|
+
*/
|
|
50
|
+
export declare function httpHarness(router: AgentRouter): HttpHarness;
|
|
51
|
+
|
|
52
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { validateParams, routerErrorToStatus } from "@rcrsr/rill-agent";
|
|
3
|
+
|
|
4
|
+
// ../../shared/hono-kit/src/index.ts
|
|
5
|
+
import { Hono } from "hono";
|
|
6
|
+
import { serve } from "@hono/node-server";
|
|
7
|
+
function assertJsonObject(parsed) {
|
|
8
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
9
|
+
throw new Error("Request body must be a JSON object");
|
|
10
|
+
}
|
|
11
|
+
return parsed;
|
|
12
|
+
}
|
|
13
|
+
function createHarnessLifecycle(options) {
|
|
14
|
+
const app = new Hono();
|
|
15
|
+
let server;
|
|
16
|
+
async function listen(port) {
|
|
17
|
+
if (server !== void 0) {
|
|
18
|
+
throw new Error("Server is already listening");
|
|
19
|
+
}
|
|
20
|
+
return new Promise((resolve) => {
|
|
21
|
+
server = serve({ fetch: app.fetch, port }, () => {
|
|
22
|
+
options?.serverTweaks?.(server);
|
|
23
|
+
resolve();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async function close() {
|
|
28
|
+
if (server !== void 0) {
|
|
29
|
+
server.close();
|
|
30
|
+
server = void 0;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return { app, listen, close };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/index.ts
|
|
37
|
+
function httpHarness(router) {
|
|
38
|
+
const lifecycle = createHarnessLifecycle();
|
|
39
|
+
const { app } = lifecycle;
|
|
40
|
+
app.get("/agents", (c) => {
|
|
41
|
+
const names = router.agents();
|
|
42
|
+
const agents = names.map((name) => ({
|
|
43
|
+
name,
|
|
44
|
+
description: router.describe(name),
|
|
45
|
+
default: name === router.defaultAgent()
|
|
46
|
+
}));
|
|
47
|
+
return c.json({ agents });
|
|
48
|
+
});
|
|
49
|
+
app.post("/agents/:name/run", async (c) => {
|
|
50
|
+
const name = c.req.param("name");
|
|
51
|
+
let body;
|
|
52
|
+
try {
|
|
53
|
+
const parsed = await c.req.json();
|
|
54
|
+
body = assertJsonObject(parsed);
|
|
55
|
+
} catch {
|
|
56
|
+
return c.json({ error: "Request body must be a JSON object" }, 400);
|
|
57
|
+
}
|
|
58
|
+
const params = body["params"] ?? {};
|
|
59
|
+
const validationError = validateParams(params, name, router);
|
|
60
|
+
if (validationError !== null) {
|
|
61
|
+
return c.json({ error: validationError }, 400);
|
|
62
|
+
}
|
|
63
|
+
const request = {
|
|
64
|
+
params,
|
|
65
|
+
...typeof body["timeout"] === "number" ? { timeout: body["timeout"] } : {}
|
|
66
|
+
};
|
|
67
|
+
try {
|
|
68
|
+
const response = await router.run(name, request);
|
|
69
|
+
return c.json(response);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
const status = routerErrorToStatus(err);
|
|
72
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
73
|
+
return c.json({ error: message }, status);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
app.post("/run", async (c) => {
|
|
77
|
+
let body;
|
|
78
|
+
try {
|
|
79
|
+
const parsed = await c.req.json();
|
|
80
|
+
body = assertJsonObject(parsed);
|
|
81
|
+
} catch {
|
|
82
|
+
return c.json({ error: "Request body must be a JSON object" }, 400);
|
|
83
|
+
}
|
|
84
|
+
const params = body["params"] ?? {};
|
|
85
|
+
const defaultName = router.defaultAgent();
|
|
86
|
+
const validationError = validateParams(params, defaultName, router);
|
|
87
|
+
if (validationError !== null) {
|
|
88
|
+
return c.json({ error: validationError }, 400);
|
|
89
|
+
}
|
|
90
|
+
const request = {
|
|
91
|
+
params,
|
|
92
|
+
...typeof body["timeout"] === "number" ? { timeout: body["timeout"] } : {}
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
const response = await router.run("", request);
|
|
96
|
+
return c.json(response);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
99
|
+
return c.json({ error: message }, 500);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
async function listen(port = 3e3) {
|
|
103
|
+
return lifecycle.listen(port);
|
|
104
|
+
}
|
|
105
|
+
return { listen, close: lifecycle.close, app };
|
|
106
|
+
}
|
|
107
|
+
export {
|
|
108
|
+
httpHarness
|
|
109
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rcrsr/rill-agent-http",
|
|
3
|
+
"version": "0.18.5",
|
|
4
|
+
"description": "rill agent HTTP harness — Hono-based HTTP server wrapping AgentRouter",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Andre Bremer",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@hono/node-server": "^1.19.12",
|
|
16
|
+
"hono": "^4.12.10",
|
|
17
|
+
"@rcrsr/rill-agent": "~0.18.5"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"dts-bundle-generator": "^9.5.1",
|
|
21
|
+
"tsup": "^8.5.0",
|
|
22
|
+
"@rcrsr/rill-agent-hono-kit": "^0.18.5"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/rcrsr/rill-agent.git",
|
|
33
|
+
"directory": "packages/agent/http"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsup && dts-bundle-generator --config dts-bundle-generator.config.cjs && node -e \"const fs=require('fs');const walk=(d)=>fs.readdirSync(d,{withFileTypes:true}).flatMap(e=>e.isDirectory()?walk(d+'/'+e.name):[d+'/'+e.name]);const hits=walk('dist').filter(f=>fs.readFileSync(f,'utf8').includes('@rcrsr/rill-agent-hono-kit'));if(hits.length){console.error('hono-kit leak in dist:',hits);process.exit(1);}\"",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"lint": "eslint --config ../../../eslint.config.js src/",
|
|
40
|
+
"check": "pnpm run build && pnpm run test && pnpm run lint"
|
|
41
|
+
}
|
|
42
|
+
}
|