@agentic-patterns/server 0.1.1 → 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.
Files changed (3) hide show
  1. package/README.md +104 -0
  2. package/package.json +13 -13
  3. package/LICENSE +0 -21
package/README.md ADDED
@@ -0,0 +1,104 @@
1
+ # @agentic-patterns/server
2
+
3
+ Hono HTTP server for agentic-patterns agents. Exposes conversation routes with SSE streaming, admin analytics, and a hook-receiver endpoint that turns Claude Code sessions into first-class events on the runtime event bus.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @agentic-patterns/server @agentic-patterns/runtime @agentic-patterns/core hono @hono/node-server
9
+ ```
10
+
11
+ Most consumers don't install this directly — `@agentic-patterns/cli` bundles it. Install standalone when you need a custom server (different framework, custom routes, non-default CORS, reverse proxy, etc.).
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { serve } from "@hono/node-server";
17
+ import {
18
+ AgentEventBus,
19
+ InMemoryAdminService,
20
+ InMemoryEventCollector,
21
+ SSEExporter,
22
+ } from "@agentic-patterns/runtime";
23
+ import { createServer } from "@agentic-patterns/server";
24
+
25
+ const bus = new AgentEventBus();
26
+ const collector = new InMemoryEventCollector();
27
+ const sse = new SSEExporter();
28
+ collector.attach(bus);
29
+ sse.attach(bus);
30
+
31
+ const app = createServer({
32
+ agents: [
33
+ /* AgentRegistration[] — built from your agents/* files or in-code */
34
+ ],
35
+ adminService: new InMemoryAdminService(collector),
36
+ eventBus: bus,
37
+ sseExporter: sse,
38
+ });
39
+
40
+ serve({ fetch: app.fetch, port: 3000 });
41
+ ```
42
+
43
+ ## Routes
44
+
45
+ | Method | Path | Purpose |
46
+ |---|---|---|
47
+ | `GET` | `/health` | Liveness probe |
48
+ | `GET` | `/agents` | List registered agents (`id`, `name`, `description`) |
49
+ | `POST` | `/conversations` | Create a new conversation with an agent |
50
+ | `POST` | `/conversations/:id/messages` | Send a message; response streams SSE frames |
51
+ | `GET` | `/admin/dashboard` | Dashboard stats snapshot |
52
+ | `GET` | `/admin/agents` | Per-agent analytics (invocations, tokens, errors) |
53
+ | `GET` | `/admin/tools` | Tool-call breakdown |
54
+ | `GET` | `/admin/tokens?group_by=agent\|model` | Token usage aggregated |
55
+ | `GET` | `/admin/events/stream` | SSE broadcast of all bus events |
56
+ | `POST` | `/hooks/:eventType` | Claude Code hook receiver (see below) |
57
+
58
+ ## SSE Event Format
59
+
60
+ `/admin/events/stream` emits frames for every event published to the bus. Event names map from internal types to canonical wire names via `SSE_EVENT_NAMES`:
61
+
62
+ ```
63
+ event: tool.start
64
+ data: {"tool_call_id":"...","tool_name":"Read","arguments":{...},"traceId":"...","timestamp":"..."}
65
+
66
+ event: claude_code.hook
67
+ data: {"hook_name":"PreToolUse","session_id":"...","tool_name":"...","tool_input":{...},"payload":{...}}
68
+
69
+ event: message.complete
70
+ data: {"content":"...","input_tokens":42,"output_tokens":128,"model":"claude-sonnet-4-..."}
71
+ ```
72
+
73
+ Consumers subscribe via `EventSource("/admin/events/stream")`.
74
+
75
+ ## Claude Code Hook Bridge
76
+
77
+ `POST /hooks/:eventType` accepts raw Claude Code lifecycle payloads and:
78
+
79
+ 1. Validates the event name against the 26 known lifecycle events (`SessionStart`, `PreToolUse`, `PreCompact`, etc.)
80
+ 2. Publishes a `ClaudeCodeHookEvent` to the bus, preserving the full raw payload
81
+ 3. Derives matching `agent.tool.start` / `agent.tool.end` events for `PreToolUse` / `PostToolUse` so standard dashboard views light up automatically
82
+ 4. If the request carries an `x-ap-runner-correlation-id` header, skips step 3 (runner already emits tool events natively)
83
+
84
+ Pair with the `hooks/emit.mjs` script shipped at the repo root — a zero-dependency Node script that reads Claude Code hook stdin and POSTs here, always exiting 0 so hooks never block the user.
85
+
86
+ ## Configuration
87
+
88
+ ```typescript
89
+ interface ServerConfig {
90
+ agents: AgentRegistration[];
91
+ adminService: AdminServiceProtocol;
92
+ eventBus: AgentEventBus;
93
+ sseExporter: SSEExporterLike;
94
+ store?: ConversationStoreLike; // optional persistence
95
+ staticDir?: string; // optional static SPA mount
96
+ cors?: CORSConfig; // defaults to origin: "*"
97
+ }
98
+ ```
99
+
100
+ For static SPA hosting (e.g., serving the admin dashboard from the same process), pass `staticDir` and the server will mount it at `/`.
101
+
102
+ ## License
103
+
104
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentic-patterns/server",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Hono HTTP server for agentic-patterns agents — routes, SSE streaming, admin API",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,11 +43,19 @@
43
43
  "files": [
44
44
  "dist"
45
45
  ],
46
+ "scripts": {
47
+ "build": "tsup",
48
+ "typecheck": "tsc --noEmit",
49
+ "test": "vitest run",
50
+ "lint": "biome check src/",
51
+ "demo": "tsx examples/live-demo.ts",
52
+ "dev": "tsx --watch examples/live-demo.ts"
53
+ },
46
54
  "dependencies": {
55
+ "@agentic-patterns/core": "0.1.2",
56
+ "@agentic-patterns/runtime": "0.1.2",
47
57
  "hono": "^4.0.0",
48
- "zod": "^3.23.0",
49
- "@agentic-patterns/core": "0.1.1",
50
- "@agentic-patterns/runtime": "0.1.1"
58
+ "zod": "^3.23.0"
51
59
  },
52
60
  "devDependencies": {
53
61
  "@hono/node-server": "^1.13.0",
@@ -56,13 +64,5 @@
56
64
  "tsx": "^4.21.0",
57
65
  "typescript": "^5.7.0",
58
66
  "vitest": "^3.0.0"
59
- },
60
- "scripts": {
61
- "build": "tsup",
62
- "typecheck": "tsc --noEmit",
63
- "test": "vitest run",
64
- "lint": "biome check src/",
65
- "demo": "tsx examples/live-demo.ts",
66
- "dev": "tsx --watch examples/live-demo.ts"
67
67
  }
68
- }
68
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Pattern Stack
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.