@rcrsr/rill-agent-http 0.18.6 → 0.20.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/index.d.ts CHANGED
@@ -2,6 +2,36 @@
2
2
 
3
3
  import { Hono } from 'hono';
4
4
 
5
+ export interface RillHarnessLogger {
6
+ info(...args: unknown[]): void;
7
+ warn(...args: unknown[]): void;
8
+ error(...args: unknown[]): void;
9
+ }
10
+ export interface RillCompiledPackage {
11
+ readonly mount: string;
12
+ readonly buildOutput: {
13
+ readonly outputPath: string;
14
+ };
15
+ }
16
+ export interface RillServeContext {
17
+ readonly config: Record<string, unknown>;
18
+ readonly logger: RillHarnessLogger;
19
+ readonly packages: readonly RillCompiledPackage[];
20
+ readonly requestedMount: string | undefined;
21
+ readonly args: readonly string[];
22
+ readonly onShutdown: (handler: () => void | Promise<void>) => void;
23
+ readonly onSourceChange: (handler: () => void | Promise<void>) => void;
24
+ }
25
+ export interface RillPostBuildContext {
26
+ readonly outputDir: string;
27
+ readonly packages: readonly RillCompiledPackage[];
28
+ readonly logger: RillHarnessLogger;
29
+ }
30
+ export interface RillHarness {
31
+ readonly name: string;
32
+ readonly postBuild?: (ctx: RillPostBuildContext) => Promise<void>;
33
+ readonly serve?: (ctx: RillServeContext) => Promise<number>;
34
+ }
5
35
  export interface HandlerDescription {
6
36
  readonly name: string;
7
37
  readonly description?: string | undefined;
@@ -12,6 +42,17 @@ export interface HandlerDescription {
12
42
  readonly description?: string | undefined;
13
43
  readonly defaultValue?: unknown;
14
44
  }>;
45
+ /**
46
+ * Handler return type annotation, formatted with the same grammar as
47
+ * parameter type strings (e.g. `stream(dict(content: string)):string`).
48
+ * Undefined when the handler closure has no `:T` annotation, or when the
49
+ * rill-build emitting the handler is too old to expose the field.
50
+ */
51
+ readonly returnType?: string | undefined;
52
+ }
53
+ export interface InitContext {
54
+ readonly globalVars?: Record<string, string> | undefined;
55
+ readonly ahiResolver?: ((agentName: string, request: RunRequest) => Promise<RunResponse>) | undefined;
15
56
  }
16
57
  export interface RunRequest {
17
58
  readonly params?: Record<string, unknown> | undefined;
@@ -21,13 +62,25 @@ export interface RunContext {
21
62
  readonly sessionVars?: Record<string, string> | undefined;
22
63
  readonly onLog?: ((message: string) => void) | undefined;
23
64
  readonly onChunk?: ((chunk: unknown) => Promise<void>) | undefined;
65
+ readonly signal?: AbortSignal | undefined;
24
66
  }
25
67
  export interface RunResponse {
26
68
  readonly state: "completed" | "error";
27
69
  readonly result: unknown;
28
70
  readonly streamed?: boolean | undefined;
29
71
  }
72
+ export interface AgentHandler {
73
+ describe(): HandlerDescription | null;
74
+ init(context?: InitContext): Promise<void>;
75
+ execute(request?: RunRequest, context?: RunContext): Promise<RunResponse>;
76
+ dispose(): Promise<void>;
77
+ }
78
+ export interface AgentManifest {
79
+ readonly defaultAgent: string;
80
+ readonly agents: ReadonlyMap<string, AgentHandler>;
81
+ }
30
82
  export interface AgentRouter {
83
+ readonly manifest: AgentManifest;
31
84
  run(agentName: string, request: RunRequest, context?: RunContext): Promise<RunResponse>;
32
85
  describe(agentName: string): HandlerDescription | null;
33
86
  agents(): string[];
@@ -48,5 +101,16 @@ export interface HttpHarness {
48
101
  * POST /run — execute the default agent
49
102
  */
50
103
  export declare function httpHarness(router: AgentRouter): HttpHarness;
104
+ /**
105
+ * Default export consumed by the rill CLI (`rill install --replace`,
106
+ * `rill run`) when this package is declared as a bundle harness. `serve`
107
+ * assembles a router from the bundle's compiled packages and hosts it over the
108
+ * HTTP harness on `config.port` (default 3000).
109
+ */
110
+ declare const harness: RillHarness;
111
+
112
+ export {
113
+ harness as default,
114
+ };
51
115
 
52
116
  export {};
package/dist/index.js CHANGED
@@ -1,7 +1,14 @@
1
1
  // src/index.ts
2
- import { validateParams, routerErrorToStatus } from "@rcrsr/rill-agent";
2
+ import {
3
+ validateParams,
4
+ routerErrorToStatus,
5
+ createRouter,
6
+ assembleManifest
7
+ } from "@rcrsr/rill-agent";
3
8
 
4
9
  // ../../shared/hono-kit/src/index.ts
10
+ import { existsSync } from "fs";
11
+ import path from "path";
5
12
  import { Hono } from "hono";
6
13
  import { serve } from "@hono/node-server";
7
14
  function assertJsonObject(parsed) {
@@ -32,8 +39,37 @@ function createHarnessLifecycle(options) {
32
39
  }
33
40
  return { app, listen, close };
34
41
  }
42
+ function compiledPackageEntries(ctx) {
43
+ return ctx.packages.map((p) => ({
44
+ name: p.mount,
45
+ dir: p.buildOutput.outputPath
46
+ }));
47
+ }
48
+ function readHarnessPort(config, fallback) {
49
+ const p = config["port"];
50
+ if (typeof p === "number" && Number.isInteger(p)) return p;
51
+ if (typeof p === "string" && /^\d+$/.test(p)) return Number(p);
52
+ return fallback;
53
+ }
54
+ function assertCompiledHandlers(ctx) {
55
+ for (const pkg of ctx.packages) {
56
+ const handlerPath = path.join(pkg.buildOutput.outputPath, "handler.js");
57
+ if (!existsSync(handlerPath)) {
58
+ throw new Error(`missing handler file: ${handlerPath}`);
59
+ }
60
+ }
61
+ }
62
+ async function runRillServe(ctx, start) {
63
+ const handle = await start(compiledPackageEntries(ctx));
64
+ ctx.onShutdown(async () => {
65
+ await handle.close();
66
+ });
67
+ return new Promise(() => {
68
+ });
69
+ }
35
70
 
36
71
  // src/index.ts
72
+ var HARNESS_NAME = "@rcrsr/rill-agent-http";
37
73
  function httpHarness(router) {
38
74
  const lifecycle = createHarnessLifecycle();
39
75
  const { app } = lifecycle;
@@ -104,6 +140,22 @@ function httpHarness(router) {
104
140
  }
105
141
  return { listen, close: lifecycle.close, app };
106
142
  }
143
+ var harness = {
144
+ name: HARNESS_NAME,
145
+ postBuild: async (ctx) => {
146
+ assertCompiledHandlers(ctx);
147
+ },
148
+ serve: (ctx) => runRillServe(ctx, async (entries) => {
149
+ const router = await createRouter(await assembleManifest(entries));
150
+ const server = httpHarness(router);
151
+ const port = readHarnessPort(ctx.config, 3e3);
152
+ await server.listen(port);
153
+ ctx.logger.info(`[${HARNESS_NAME}] listening on :${port}`);
154
+ return server;
155
+ })
156
+ };
157
+ var index_default = harness;
107
158
  export {
159
+ index_default as default,
108
160
  httpHarness
109
161
  };
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@rcrsr/rill-agent-http",
3
- "version": "0.18.6",
3
+ "version": "0.20.0",
4
4
  "description": "rill agent HTTP harness — Hono-based HTTP server wrapping AgentRouter",
5
5
  "license": "MIT",
6
6
  "author": "Andre Bremer",
7
7
  "type": "module",
8
+ "rill": {
9
+ "role": "harness"
10
+ },
8
11
  "exports": {
9
12
  ".": {
10
13
  "types": "./dist/index.d.ts",
@@ -12,14 +15,14 @@
12
15
  }
13
16
  },
14
17
  "dependencies": {
15
- "@hono/node-server": "^1.19.12",
16
- "hono": "^4.12.10",
17
- "@rcrsr/rill-agent": "~0.18.6"
18
+ "@hono/node-server": "^2.0.1",
19
+ "hono": "^4.12.16",
20
+ "@rcrsr/rill-agent": "~0.20.0"
18
21
  },
19
22
  "devDependencies": {
20
23
  "dts-bundle-generator": "^9.5.1",
21
24
  "tsup": "^8.5.0",
22
- "@rcrsr/rill-agent-hono-kit": "^0.18.6"
25
+ "@rcrsr/rill-agent-hono-kit": "^0.20.0"
23
26
  },
24
27
  "files": [
25
28
  "dist"
@@ -36,7 +39,7 @@
36
39
  "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
40
  "test": "vitest run",
38
41
  "typecheck": "tsc --noEmit",
39
- "lint": "eslint --config ../../../eslint.config.js src/",
42
+ "lint": "oxlint --config ../../../.oxlintrc.json src/ tests/",
40
43
  "check": "pnpm run build && pnpm run test && pnpm run lint"
41
44
  }
42
45
  }