@achieveai/hitl-mcp-server 1.0.1 → 1.2.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/README.md +159 -43
- package/config/claude-desktop.json +2 -2
- package/config/cursor-mcp.json +2 -3
- package/config/vscode-mcp.json +1 -1
- package/dist/__tests__/dialog-manager.test.js +4 -4
- package/dist/__tests__/dialog-manager.test.js.map +1 -1
- package/dist/dialog-manager.d.ts +1 -0
- package/dist/dialog-manager.d.ts.map +1 -1
- package/dist/dialog-manager.js +176 -9
- package/dist/dialog-manager.js.map +1 -1
- package/dist/index.js +51 -24
- package/dist/index.js.map +1 -1
- package/dist/test-client.js +15 -1
- package/dist/test-client.js.map +1 -1
- package/dist/test-dialog-manager.d.ts +2 -0
- package/dist/test-dialog-manager.d.ts.map +1 -0
- package/dist/test-dialog-manager.js +156 -0
- package/dist/test-dialog-manager.js.map +1 -0
- package/package.json +2 -1
- package/sounds/notification.wav +0 -0
package/README.md
CHANGED
|
@@ -1,15 +1,61 @@
|
|
|
1
1
|
# Human In The Loop MCP Server
|
|
2
2
|
|
|
3
|
-
A Model Context Protocol (MCP) server that
|
|
3
|
+
A Model Context Protocol (MCP) server that bridges the gap between AI autonomy and human oversight by enabling LLM agents to request human input at critical decision points.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## What This Tool Does
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
-
|
|
7
|
+
This MCP server allows AI agents like Claude to pause their execution and ask humans for guidance through interactive browser-based dialogs. Instead of making assumptions or failing when faced with ambiguity, AI agents can now gracefully request human input and continue with confidence.
|
|
8
|
+
|
|
9
|
+
## Real-World Use Cases
|
|
10
|
+
|
|
11
|
+
### 1. **Code Generation Decisions**
|
|
12
|
+
When generating code, the AI can ask:
|
|
13
|
+
- "Which framework should I use: React, Vue, or Angular?"
|
|
14
|
+
- "Should I implement this with TypeScript or JavaScript?"
|
|
15
|
+
- "Which testing framework do you prefer?"
|
|
16
|
+
|
|
17
|
+
### 2. **Deployment & Operations**
|
|
18
|
+
- "Ready to deploy to production? I've run all tests."
|
|
19
|
+
- "Should I rollback the deployment? Errors detected."
|
|
20
|
+
- "Which environment: staging or production?"
|
|
21
|
+
|
|
22
|
+
### 3. **Data Processing**
|
|
23
|
+
- "Found 1000 duplicate records. Delete all, keep first, or review manually?"
|
|
24
|
+
- "Which columns should I include in the export?"
|
|
25
|
+
- "Normalize the data using method A (faster) or B (more accurate)?"
|
|
26
|
+
|
|
27
|
+
### 4. **Content & Documentation**
|
|
28
|
+
- "Which tone for the documentation: formal, casual, or technical?"
|
|
29
|
+
- "Include code examples in the README?"
|
|
30
|
+
- "Which sections are most important for your users?"
|
|
31
|
+
|
|
32
|
+
### 5. **Git Operations**
|
|
33
|
+
- "Which files should I include in this commit?"
|
|
34
|
+
- "Merge conflict detected. Keep theirs, ours, or manual review?"
|
|
35
|
+
- "Create a new branch or commit to main?"
|
|
36
|
+
|
|
37
|
+
## What to Expect
|
|
38
|
+
|
|
39
|
+
### For Developers
|
|
40
|
+
- **Reduced Errors**: AI agents won't make incorrect assumptions about your preferences
|
|
41
|
+
- **Better Control**: Maintain oversight of critical decisions while letting AI handle the implementation
|
|
42
|
+
- **Improved Workflow**: AI can complete complex multi-step tasks with human guidance at key points
|
|
43
|
+
- **Time Savings**: Let AI do the work while you just make the important decisions
|
|
44
|
+
|
|
45
|
+
### For AI Agents
|
|
46
|
+
- **Clear Decision Points**: No more guessing what the user wants
|
|
47
|
+
- **Graceful Handling**: Ambiguous situations become opportunities for clarification
|
|
48
|
+
- **Better Results**: Human input ensures the output matches expectations
|
|
49
|
+
- **Continuous Workflow**: Complete tasks without stopping for every small decision
|
|
50
|
+
|
|
51
|
+
## Core Features
|
|
52
|
+
|
|
53
|
+
- **Browser-Based Dialogs**: Clean, accessible UI that opens automatically
|
|
54
|
+
- **Multiple Choice Support**: Single or multi-select options with descriptions
|
|
55
|
+
- **Custom Input**: "Other" field for responses not in the list
|
|
56
|
+
- **Timeout Support**: Auto-dismiss dialogs after specified time
|
|
10
57
|
- **Cross-Platform**: Works on Windows, macOS, and Linux
|
|
11
|
-
- **
|
|
12
|
-
- **STDIO Transport**: Easy integration with Claude Desktop and other MCP clients
|
|
58
|
+
- **Zero Configuration**: Works out of the box with sensible defaults
|
|
13
59
|
|
|
14
60
|
## Installation
|
|
15
61
|
|
|
@@ -18,12 +64,29 @@ A Model Context Protocol (MCP) server that enables LLM agents to request human i
|
|
|
18
64
|
- Node.js 18+ and npm
|
|
19
65
|
- A browser (for displaying dialogs)
|
|
20
66
|
|
|
67
|
+
### Quick Install from NPM
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Install globally from npm
|
|
71
|
+
npm install -g @achieveai/hitl-mcp-server
|
|
72
|
+
|
|
73
|
+
# Now you can run it from anywhere
|
|
74
|
+
hitl-mcp-server
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Using with npx (no installation required)
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
# Run directly without installing
|
|
81
|
+
npx @achieveai/hitl-mcp-server
|
|
82
|
+
```
|
|
83
|
+
|
|
21
84
|
### From Source
|
|
22
85
|
|
|
23
86
|
```bash
|
|
24
87
|
# Clone the repository
|
|
25
|
-
git clone
|
|
26
|
-
cd hitl-mcp-server
|
|
88
|
+
git clone https://github.com/achieveai/HumanInTheLoop.git
|
|
89
|
+
cd HumanInTheLoop/hitl-mcp-server
|
|
27
90
|
|
|
28
91
|
# Install dependencies
|
|
29
92
|
npm install
|
|
@@ -35,19 +98,6 @@ npm run build
|
|
|
35
98
|
npm run dev
|
|
36
99
|
```
|
|
37
100
|
|
|
38
|
-
### Global Installation
|
|
39
|
-
|
|
40
|
-
```bash
|
|
41
|
-
# Build first
|
|
42
|
-
npm run build
|
|
43
|
-
|
|
44
|
-
# Install globally
|
|
45
|
-
npm install -g .
|
|
46
|
-
|
|
47
|
-
# Now you can run it from anywhere
|
|
48
|
-
hitl-mcp-server
|
|
49
|
-
```
|
|
50
|
-
|
|
51
101
|
## Configuration
|
|
52
102
|
|
|
53
103
|
Pre-configured examples are available in the `config/` directory for different MCP clients.
|
|
@@ -64,8 +114,23 @@ Add the server to your Claude Desktop config file:
|
|
|
64
114
|
{
|
|
65
115
|
"mcpServers": {
|
|
66
116
|
"human-in-the-loop": {
|
|
67
|
-
"command": "
|
|
68
|
-
"args": ["
|
|
117
|
+
"command": "npx",
|
|
118
|
+
"args": ["-y", "@achieveai/hitl-mcp-server"],
|
|
119
|
+
"env": {
|
|
120
|
+
"NODE_ENV": "production"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Or if you've installed it globally:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"mcpServers": {
|
|
132
|
+
"human-in-the-loop": {
|
|
133
|
+
"command": "hitl-mcp-server",
|
|
69
134
|
"env": {
|
|
70
135
|
"NODE_ENV": "production"
|
|
71
136
|
}
|
|
@@ -83,7 +148,7 @@ Create `.vscode/mcp.json` in your workspace:
|
|
|
83
148
|
"mcpServers": {
|
|
84
149
|
"human-in-the-loop": {
|
|
85
150
|
"command": "npx",
|
|
86
|
-
"args": ["-y", "@hitl
|
|
151
|
+
"args": ["-y", "@achieveai/hitl-mcp-server"],
|
|
87
152
|
"env": {
|
|
88
153
|
"NODE_ENV": "production"
|
|
89
154
|
}
|
|
@@ -101,9 +166,8 @@ Add to your Cursor settings:
|
|
|
101
166
|
"mcpServers": {
|
|
102
167
|
"human-in-the-loop": {
|
|
103
168
|
"name": "Human In The Loop",
|
|
104
|
-
"command": "
|
|
105
|
-
"args": ["
|
|
106
|
-
"cwd": "D:\\Source\\repos\\Hitl_MCP\\hitl-mcp-server",
|
|
169
|
+
"command": "npx",
|
|
170
|
+
"args": ["-y", "@achieveai/hitl-mcp-server"],
|
|
107
171
|
"transport": "stdio",
|
|
108
172
|
"autoStart": false
|
|
109
173
|
}
|
|
@@ -111,22 +175,41 @@ Add to your Cursor settings:
|
|
|
111
175
|
}
|
|
112
176
|
```
|
|
113
177
|
|
|
114
|
-
|
|
178
|
+
Or if you've installed it globally:
|
|
115
179
|
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"mcpServers": {
|
|
183
|
+
"human-in-the-loop": {
|
|
184
|
+
"name": "Human In The Loop",
|
|
185
|
+
"command": "hitl-mcp-server",
|
|
186
|
+
"transport": "stdio",
|
|
187
|
+
"autoStart": false
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Recommended Configuration
|
|
119
194
|
|
|
120
|
-
|
|
195
|
+
For all MCP clients, we recommend using npx for zero-installation setup:
|
|
196
|
+
|
|
197
|
+
```json
|
|
121
198
|
{
|
|
122
199
|
"mcpServers": {
|
|
123
200
|
"human-in-the-loop": {
|
|
124
|
-
"command": "
|
|
201
|
+
"command": "npx",
|
|
202
|
+
"args": ["-y", "@achieveai/hitl-mcp-server"]
|
|
125
203
|
}
|
|
126
204
|
}
|
|
127
205
|
}
|
|
128
206
|
```
|
|
129
207
|
|
|
208
|
+
This approach:
|
|
209
|
+
- Requires no installation
|
|
210
|
+
- Always uses the latest version
|
|
211
|
+
- Works immediately on any system with Node.js
|
|
212
|
+
|
|
130
213
|
## Usage
|
|
131
214
|
|
|
132
215
|
Once configured, the AI agent can use the `ask_human` tool to request input:
|
|
@@ -266,17 +349,43 @@ hitl-mcp-server/
|
|
|
266
349
|
- `npm test` - Run unit tests
|
|
267
350
|
- `npm run typecheck` - Check TypeScript types without building
|
|
268
351
|
|
|
269
|
-
## Why
|
|
352
|
+
## Why This Tool Matters
|
|
353
|
+
|
|
354
|
+
### The Problem
|
|
355
|
+
AI agents are powerful but often encounter situations where they need human judgment:
|
|
356
|
+
- Ambiguous requirements that could be interpreted multiple ways
|
|
357
|
+
- Critical decisions that could have significant consequences
|
|
358
|
+
- Subjective choices about style, approach, or priorities
|
|
359
|
+
- Missing context that only the human user possesses
|
|
360
|
+
|
|
361
|
+
### The Solution
|
|
362
|
+
This tool creates a seamless communication channel between AI and humans:
|
|
363
|
+
- **AI Autonomy**: The agent continues working independently until it needs input
|
|
364
|
+
- **Human Control**: You maintain oversight of important decisions
|
|
365
|
+
- **Efficient Workflow**: No need to micromanage - only intervene when necessary
|
|
366
|
+
- **Better Outcomes**: Combine AI efficiency with human judgment
|
|
270
367
|
|
|
271
|
-
|
|
368
|
+
### Expected Benefits
|
|
272
369
|
|
|
273
|
-
1. **
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
5. **Subjective Choices**: Design decisions, naming conventions, etc.
|
|
370
|
+
1. **Increased Productivity**
|
|
371
|
+
- Let AI handle implementation while you focus on decisions
|
|
372
|
+
- Batch multiple tasks with decision points
|
|
373
|
+
- Reduce back-and-forth clarifications
|
|
278
374
|
|
|
279
|
-
|
|
375
|
+
2. **Improved Accuracy**
|
|
376
|
+
- No more AI guessing your preferences
|
|
377
|
+
- Catch potential issues before they happen
|
|
378
|
+
- Ensure outputs match your expectations
|
|
379
|
+
|
|
380
|
+
3. **Enhanced Trust**
|
|
381
|
+
- Know that AI will ask before making critical changes
|
|
382
|
+
- Review and approve important decisions
|
|
383
|
+
- Maintain control while leveraging AI capabilities
|
|
384
|
+
|
|
385
|
+
4. **Seamless Integration**
|
|
386
|
+
- Works with Claude Desktop, Cursor, VS Code, and other MCP clients
|
|
387
|
+
- No complex setup or configuration required
|
|
388
|
+
- Natural integration into existing AI workflows
|
|
280
389
|
|
|
281
390
|
## Troubleshooting
|
|
282
391
|
|
|
@@ -297,9 +406,16 @@ This tool ensures AI agents can gracefully handle these situations by requesting
|
|
|
297
406
|
- Verify Node.js version is 18 or higher
|
|
298
407
|
- Run `npm install` to ensure all dependencies are installed
|
|
299
408
|
|
|
409
|
+
## Security & Privacy
|
|
410
|
+
|
|
411
|
+
- All dialogs run locally on your machine
|
|
412
|
+
- No data is sent to external servers
|
|
413
|
+
- Dialog server only accepts connections from localhost
|
|
414
|
+
- Temporary server instances are created per request
|
|
415
|
+
|
|
300
416
|
## License
|
|
301
417
|
|
|
302
|
-
|
|
418
|
+
GPL-3.0
|
|
303
419
|
|
|
304
420
|
## Contributing
|
|
305
421
|
|
package/config/cursor-mcp.json
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
"human-in-the-loop": {
|
|
4
4
|
"name": "Human In The Loop",
|
|
5
5
|
"description": "Interactive dialog system for getting human feedback",
|
|
6
|
-
"command": "
|
|
7
|
-
"args": ["
|
|
8
|
-
"cwd": "D:\\Source\\repos\\Hitl_MCP\\hitl-mcp-server",
|
|
6
|
+
"command": "npx",
|
|
7
|
+
"args": ["-y", "@achieveai/hitl-mcp-server"],
|
|
9
8
|
"env": {
|
|
10
9
|
"NODE_ENV": "production"
|
|
11
10
|
},
|
package/config/vscode-mcp.json
CHANGED
|
@@ -106,8 +106,8 @@ describe('DialogManager', () => {
|
|
|
106
106
|
allowMultiple: false,
|
|
107
107
|
allowOther: true
|
|
108
108
|
});
|
|
109
|
-
expect(html).toContain('other-input');
|
|
110
|
-
expect(html).toContain('
|
|
109
|
+
expect(html).toContain('id="other-input"');
|
|
110
|
+
expect(html).toContain('Additional Context (optional)');
|
|
111
111
|
});
|
|
112
112
|
it('should not include other field when not allowed', () => {
|
|
113
113
|
const manager = new DialogManager();
|
|
@@ -118,8 +118,8 @@ describe('DialogManager', () => {
|
|
|
118
118
|
allowMultiple: false,
|
|
119
119
|
allowOther: false
|
|
120
120
|
});
|
|
121
|
-
expect(html).not.toContain('other-input');
|
|
122
|
-
expect(html).not.toContain('
|
|
121
|
+
expect(html).not.toContain('id="other-input"');
|
|
122
|
+
expect(html).not.toContain('Additional Context (optional)');
|
|
123
123
|
});
|
|
124
124
|
});
|
|
125
125
|
describe('timeout handling', () => {
|
|
@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AAC,UAAU,CAAC;gBACvC,EAAE,EAAE,cAAc;gBAClB,QAAQ,EAAE,mBAAmB;gBAC7B,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;gBAC5C,aAAa,EAAE,KAAK;gBACpB,UAAU,EAAE,KAAK;gBACjB,OAAO,EAAE,GAAG;aACb,CAAC,CAAC;YAEH,MAAM,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QAChE,CAAC,EAAE,KAAK,CAAC,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/dialog-manager.d.ts
CHANGED
|
@@ -31,6 +31,7 @@ export declare class DialogManager extends EventEmitter {
|
|
|
31
31
|
private escapeHtml;
|
|
32
32
|
initialize(): Promise<number>;
|
|
33
33
|
showDialog(request: DialogRequest): Promise<DialogResponse>;
|
|
34
|
+
private playNotificationSound;
|
|
34
35
|
close(): Promise<void>;
|
|
35
36
|
}
|
|
36
37
|
//# sourceMappingURL=dialog-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-manager.d.ts","sourceRoot":"","sources":["../src/dialog-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"dialog-manager.d.ts","sourceRoot":"","sources":["../src/dialog-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAQtC,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC7C,OAAO,CAAC,GAAG,CAAU;IACrB,OAAO,CAAC,IAAI,CAAS;IACrB,OAAO,CAAC,cAAc,CAKnB;IACH,OAAO,CAAC,MAAM,CAAM;IACpB,OAAO,CAAC,aAAa,CAAkB;gBAE3B,IAAI,GAAE,MAAU;IAQ5B,OAAO,CAAC,WAAW;IAgDnB,OAAO,CAAC,kBAAkB;IAqd1B,OAAO,CAAC,UAAU;IAWZ,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAoB7B,UAAU,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAqCjE,OAAO,CAAC,qBAAqB;IA+CvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAU7B"}
|
package/dist/dialog-manager.js
CHANGED
|
@@ -2,6 +2,11 @@ import express from 'express';
|
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
import open from 'open';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
|
+
import { exec } from 'child_process';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
5
10
|
export class DialogManager extends EventEmitter {
|
|
6
11
|
app;
|
|
7
12
|
port;
|
|
@@ -59,6 +64,7 @@ export class DialogManager extends EventEmitter {
|
|
|
59
64
|
<meta charset="UTF-8">
|
|
60
65
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
61
66
|
<title>Human In The Loop - Response Required</title>
|
|
67
|
+
<script src="https://cdn.jsdelivr.net/npm/marked@11.1.1/lib/marked.umd.min.js"></script>
|
|
62
68
|
<style>
|
|
63
69
|
* {
|
|
64
70
|
margin: 0;
|
|
@@ -69,7 +75,9 @@ export class DialogManager extends EventEmitter {
|
|
|
69
75
|
body {
|
|
70
76
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
71
77
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
72
|
-
|
|
78
|
+
height: 100vh;
|
|
79
|
+
max-height: 100vh;
|
|
80
|
+
overflow-y: auto;
|
|
73
81
|
display: flex;
|
|
74
82
|
justify-content: center;
|
|
75
83
|
align-items: center;
|
|
@@ -82,6 +90,8 @@ export class DialogManager extends EventEmitter {
|
|
|
82
90
|
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
|
|
83
91
|
max-width: 600px;
|
|
84
92
|
width: 100%;
|
|
93
|
+
max-height: 90vh;
|
|
94
|
+
overflow-y: auto;
|
|
85
95
|
padding: 32px;
|
|
86
96
|
animation: slideIn 0.3s ease-out;
|
|
87
97
|
}
|
|
@@ -128,6 +138,90 @@ export class DialogManager extends EventEmitter {
|
|
|
128
138
|
font-size: 14px;
|
|
129
139
|
color: #4a5568;
|
|
130
140
|
border-radius: 4px;
|
|
141
|
+
max-height: 200px;
|
|
142
|
+
overflow-y: auto;
|
|
143
|
+
line-height: 1.6;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* Markdown styling in context */
|
|
147
|
+
.context strong {
|
|
148
|
+
font-weight: 600;
|
|
149
|
+
color: #2d3748;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.context code {
|
|
153
|
+
background: #e2e8f0;
|
|
154
|
+
padding: 2px 6px;
|
|
155
|
+
border-radius: 3px;
|
|
156
|
+
font-family: 'Courier New', monospace;
|
|
157
|
+
font-size: 13px;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
.context pre {
|
|
161
|
+
background: #2d3748;
|
|
162
|
+
color: #f7fafc;
|
|
163
|
+
padding: 12px;
|
|
164
|
+
border-radius: 6px;
|
|
165
|
+
overflow-x: auto;
|
|
166
|
+
margin: 8px 0;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.context pre code {
|
|
170
|
+
background: transparent;
|
|
171
|
+
color: inherit;
|
|
172
|
+
padding: 0;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.context ul, .context ol {
|
|
176
|
+
margin-left: 20px;
|
|
177
|
+
margin-top: 8px;
|
|
178
|
+
margin-bottom: 8px;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.context li {
|
|
182
|
+
margin: 4px 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.context p {
|
|
186
|
+
margin: 8px 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.context h1, .context h2, .context h3 {
|
|
190
|
+
margin-top: 12px;
|
|
191
|
+
margin-bottom: 8px;
|
|
192
|
+
color: #2d3748;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.context a {
|
|
196
|
+
color: #667eea;
|
|
197
|
+
text-decoration: underline;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.context blockquote {
|
|
201
|
+
border-left: 3px solid #cbd5e0;
|
|
202
|
+
padding-left: 12px;
|
|
203
|
+
margin: 8px 0;
|
|
204
|
+
color: #718096;
|
|
205
|
+
font-style: italic;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/* Custom scrollbar for context */
|
|
209
|
+
.context::-webkit-scrollbar {
|
|
210
|
+
width: 8px;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.context::-webkit-scrollbar-track {
|
|
214
|
+
background: #e2e8f0;
|
|
215
|
+
border-radius: 4px;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.context::-webkit-scrollbar-thumb {
|
|
219
|
+
background: #cbd5e0;
|
|
220
|
+
border-radius: 4px;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.context::-webkit-scrollbar-thumb:hover {
|
|
224
|
+
background: #a0aec0;
|
|
131
225
|
}
|
|
132
226
|
|
|
133
227
|
.options-container {
|
|
@@ -259,7 +353,8 @@ export class DialogManager extends EventEmitter {
|
|
|
259
353
|
|
|
260
354
|
${request.context ? `
|
|
261
355
|
<div class="context">
|
|
262
|
-
<strong>Context:</strong>
|
|
356
|
+
<strong>Context:</strong>
|
|
357
|
+
<div id="context-content"></div>
|
|
263
358
|
</div>
|
|
264
359
|
` : ''}
|
|
265
360
|
|
|
@@ -282,11 +377,11 @@ export class DialogManager extends EventEmitter {
|
|
|
282
377
|
|
|
283
378
|
${request.allowOther ? `
|
|
284
379
|
<div class="other-section">
|
|
285
|
-
<label class="other-label" for="other-input">
|
|
286
|
-
<textarea class="other-input"
|
|
287
|
-
id="other-input"
|
|
288
|
-
rows="3"
|
|
289
|
-
placeholder="
|
|
380
|
+
<label class="other-label" for="other-input">Additional Context (optional):</label>
|
|
381
|
+
<textarea class="other-input"
|
|
382
|
+
id="other-input"
|
|
383
|
+
rows="3"
|
|
384
|
+
placeholder="Provide any additional context, clarifications, or notes to help guide the AI..."></textarea>
|
|
290
385
|
</div>
|
|
291
386
|
` : ''}
|
|
292
387
|
|
|
@@ -302,6 +397,7 @@ export class DialogManager extends EventEmitter {
|
|
|
302
397
|
const dialogId = '${request.id}';
|
|
303
398
|
const allowMultiple = ${request.allowMultiple};
|
|
304
399
|
const allowOther = ${request.allowOther};
|
|
400
|
+
const contextMarkdown = ${request.context ? JSON.stringify(request.context) : 'null'};
|
|
305
401
|
|
|
306
402
|
function toggleOption(index) {
|
|
307
403
|
const option = document.getElementById('option-' + index);
|
|
@@ -335,9 +431,9 @@ export class DialogManager extends EventEmitter {
|
|
|
335
431
|
async function submitResponse() {
|
|
336
432
|
const selectedValues = getSelectedValues();
|
|
337
433
|
const otherText = allowOther ? document.getElementById('other-input').value.trim() : '';
|
|
338
|
-
|
|
434
|
+
|
|
339
435
|
if (selectedValues.length === 0 && !otherText) {
|
|
340
|
-
showError('Please select at least one option or provide
|
|
436
|
+
showError('Please select at least one option and/or provide additional context');
|
|
341
437
|
return;
|
|
342
438
|
}
|
|
343
439
|
|
|
@@ -404,6 +500,27 @@ export class DialogManager extends EventEmitter {
|
|
|
404
500
|
}
|
|
405
501
|
});
|
|
406
502
|
}
|
|
503
|
+
|
|
504
|
+
// Note: Sound notification is played from the server before opening the browser
|
|
505
|
+
// No client-side sound needed
|
|
506
|
+
|
|
507
|
+
// Render markdown in context
|
|
508
|
+
if (contextMarkdown && typeof marked !== 'undefined') {
|
|
509
|
+
const contextElement = document.getElementById('context-content');
|
|
510
|
+
if (contextElement) {
|
|
511
|
+
try {
|
|
512
|
+
// Configure marked for safe HTML rendering
|
|
513
|
+
marked.setOptions({
|
|
514
|
+
breaks: true,
|
|
515
|
+
gfm: true
|
|
516
|
+
});
|
|
517
|
+
contextElement.innerHTML = marked.parse(contextMarkdown);
|
|
518
|
+
} catch (error) {
|
|
519
|
+
// Fallback to plain text if markdown parsing fails
|
|
520
|
+
contextElement.textContent = contextMarkdown;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
407
524
|
</script>
|
|
408
525
|
</body>
|
|
409
526
|
</html>`;
|
|
@@ -457,12 +574,62 @@ export class DialogManager extends EventEmitter {
|
|
|
457
574
|
});
|
|
458
575
|
const dialogUrl = `http://localhost:${this.port}/dialog/${dialogId}`;
|
|
459
576
|
console.error(`Opening dialog: ${dialogUrl}`);
|
|
577
|
+
// Play notification sound from server before opening browser
|
|
578
|
+
this.playNotificationSound();
|
|
460
579
|
open(dialogUrl).catch((err) => {
|
|
461
580
|
console.error('Failed to open browser:', err);
|
|
462
581
|
console.error(`Please manually open: ${dialogUrl}`);
|
|
463
582
|
});
|
|
464
583
|
});
|
|
465
584
|
}
|
|
585
|
+
playNotificationSound() {
|
|
586
|
+
try {
|
|
587
|
+
// Path to bundled notification sound (relative to dist folder) - used as fallback
|
|
588
|
+
const bundledSound = path.join(__dirname, '..', 'sounds', 'notification.wav');
|
|
589
|
+
if (process.platform === 'win32') {
|
|
590
|
+
// Windows: Try system sound first, then fall back to bundled sound
|
|
591
|
+
const systemSound = 'C:\\Windows\\Media\\Windows Notify Messaging.wav';
|
|
592
|
+
const script = `(New-Object Media.SoundPlayer '${systemSound}').PlaySync()`;
|
|
593
|
+
exec(`powershell -c "${script}"`, (error) => {
|
|
594
|
+
if (error) {
|
|
595
|
+
// Fallback to bundled custom sound
|
|
596
|
+
const fallbackScript = `(New-Object Media.SoundPlayer '${bundledSound}').PlaySync()`;
|
|
597
|
+
exec(`powershell -c "${fallbackScript}"`, (err2) => {
|
|
598
|
+
if (err2) {
|
|
599
|
+
// Final fallback to beeps
|
|
600
|
+
const beepScript = '[console]::beep(659,150); [console]::beep(880,200)';
|
|
601
|
+
exec(`powershell -c "${beepScript}"`, () => {
|
|
602
|
+
process.stdout.write('\x07');
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
else if (process.platform === 'darwin') {
|
|
610
|
+
// macOS: Use system sound, fall back to bundled sound
|
|
611
|
+
exec('afplay /System/Library/Sounds/Glass.aiff', (error) => {
|
|
612
|
+
if (error) {
|
|
613
|
+
exec(`afplay "${bundledSound}"`, () => {
|
|
614
|
+
process.stdout.write('\x07');
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
// Linux: Try system sound, fall back to bundled sound
|
|
621
|
+
exec(`paplay /usr/share/sounds/freedesktop/stereo/message.oga 2>/dev/null || paplay "${bundledSound}" 2>/dev/null || beep || echo -en "\\a"`, (error) => {
|
|
622
|
+
if (error) {
|
|
623
|
+
process.stdout.write('\x07');
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
catch (error) {
|
|
629
|
+
// Ultimate fallback: ASCII bell character
|
|
630
|
+
process.stdout.write('\x07');
|
|
631
|
+
}
|
|
632
|
+
}
|
|
466
633
|
async close() {
|
|
467
634
|
if (this.server) {
|
|
468
635
|
return new Promise((resolve) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog-manager.js","sourceRoot":"","sources":["../src/dialog-manager.ts"],"names":[],"mappings":"AAAA,OAAO,OAAuC,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"dialog-manager.js","sourceRoot":"","sources":["../src/dialog-manager.ts"],"names":[],"mappings":"AAAA,OAAO,OAAuC,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAyB3C,MAAM,OAAO,aAAc,SAAQ,YAAY;IACrC,GAAG,CAAU;IACb,IAAI,CAAS;IACb,cAAc,CAKnB;IACK,MAAM,CAAM;IACZ,aAAa,GAAY,KAAK,CAAC;IAEvC,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C,KAAK,CAAC,MAAM,CAAC,CAAC;oBAC/B,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,0CAA0C;YAC1C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE;oBACrB,IAAI,CAAC,aAAa,GAAG,KAAK,CAAC;oBAC3B,OAAO,EAAE,CAAC;gBACZ,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -27,17 +27,28 @@ class HumanInTheLoopServer {
|
|
|
27
27
|
tools: [
|
|
28
28
|
{
|
|
29
29
|
name: TOOL_NAME,
|
|
30
|
-
description: `CRITICAL: Use this tool
|
|
31
|
-
• Resolving ambiguities or unclear requirements
|
|
32
|
-
• Making subjective decisions that require human judgment
|
|
33
|
-
• Choosing between multiple valid approaches
|
|
34
|
-
• Confirming critical actions before execution
|
|
35
|
-
• Getting additional context or clarification
|
|
36
|
-
• Handling edge cases not covered by your instructions
|
|
30
|
+
description: `CRITICAL: Use this tool whenever you have ANY doubt or need human decision-making. This tool is ESSENTIAL for:
|
|
37
31
|
|
|
38
|
-
|
|
32
|
+
WHEN TO USE (err on the side of asking):
|
|
33
|
+
• You have even slight uncertainty about what the user wants
|
|
34
|
+
• You need clarification on ambiguous requirements or instructions
|
|
35
|
+
• The user explicitly told you to ask for their input on decisions
|
|
36
|
+
• Multiple valid approaches exist and you're unsure which to choose
|
|
37
|
+
• A decision could have significant consequences
|
|
38
|
+
• You're about to make assumptions that might be wrong
|
|
39
|
+
• You need confirmation before critical or irreversible actions
|
|
40
|
+
• You need additional context not provided in your instructions
|
|
39
41
|
|
|
40
|
-
|
|
42
|
+
HOW TO USE:
|
|
43
|
+
• Provide clear, specific options for the human to choose from
|
|
44
|
+
• Think carefully about which option you would recommend and mark it with "(RECOMMENDED)" in the label
|
|
45
|
+
Example: { label: "PostgreSQL (RECOMMENDED)", value: "postgres", description: "Best for complex queries" }
|
|
46
|
+
• The human can select one or more options AND provide additional context
|
|
47
|
+
• The "(RECOMMENDED)" marker helps guide the user but won't appear in the returned value
|
|
48
|
+
|
|
49
|
+
This tool opens an interactive browser dialog with a pleasant notification sound. The human can select options and optionally provide additional context to guide your next steps.
|
|
50
|
+
|
|
51
|
+
IMPORTANT: When in doubt, ASK. Using this tool is far better than making incorrect assumptions. Getting human input ensures accuracy and alignment with user expectations.`,
|
|
41
52
|
inputSchema: {
|
|
42
53
|
type: 'object',
|
|
43
54
|
properties: {
|
|
@@ -71,11 +82,11 @@ IMPORTANT: Prefer using this tool over making assumptions or returning incomplet
|
|
|
71
82
|
allowMultiple: {
|
|
72
83
|
type: 'boolean',
|
|
73
84
|
description: 'Whether to allow selecting multiple options (checkbox vs radio)',
|
|
74
|
-
default:
|
|
85
|
+
default: true
|
|
75
86
|
},
|
|
76
87
|
allowOther: {
|
|
77
88
|
type: 'boolean',
|
|
78
|
-
description: 'Whether to show an "
|
|
89
|
+
description: 'Whether to show an "Additional Context" text field where the user can provide supplementary information alongside their selection(s)',
|
|
79
90
|
default: true
|
|
80
91
|
},
|
|
81
92
|
context: {
|
|
@@ -112,11 +123,15 @@ IMPORTANT: Prefer using this tool over making assumptions or returning incomplet
|
|
|
112
123
|
id: uuidv4(),
|
|
113
124
|
question: args.question,
|
|
114
125
|
options: dialogOptions,
|
|
115
|
-
allowMultiple: args.allowMultiple
|
|
126
|
+
allowMultiple: args.allowMultiple !== false,
|
|
116
127
|
allowOther: args.allowOther !== false,
|
|
117
128
|
context: args.context,
|
|
118
129
|
timeout: args.timeout
|
|
119
130
|
});
|
|
131
|
+
// Helper function to strip (RECOMMENDED) markers from values
|
|
132
|
+
const stripRecommended = (value) => {
|
|
133
|
+
return value.replace(/\s*\(RECOMMENDED\)\s*/gi, '').trim();
|
|
134
|
+
};
|
|
120
135
|
let result = {
|
|
121
136
|
success: true,
|
|
122
137
|
timestamp: response.timestamp
|
|
@@ -124,20 +139,32 @@ IMPORTANT: Prefer using this tool over making assumptions or returning incomplet
|
|
|
124
139
|
if (response.otherText === 'SKIPPED') {
|
|
125
140
|
result.skipped = true;
|
|
126
141
|
result.response = 'User skipped this question';
|
|
127
|
-
|
|
128
|
-
else if (response.otherText && response.otherText !== '') {
|
|
129
|
-
result.response = response.otherText;
|
|
130
|
-
result.responseType = 'custom';
|
|
131
|
-
}
|
|
132
|
-
else if (response.selectedValues.length > 0) {
|
|
133
|
-
result.response = args.allowMultiple
|
|
134
|
-
? response.selectedValues
|
|
135
|
-
: response.selectedValues[0];
|
|
136
|
-
result.responseType = 'selection';
|
|
142
|
+
result.responseType = 'skipped';
|
|
137
143
|
}
|
|
138
144
|
else {
|
|
139
|
-
|
|
140
|
-
|
|
145
|
+
// Clean the selected values
|
|
146
|
+
const cleanedValues = response.selectedValues.map(stripRecommended);
|
|
147
|
+
// Include selected values if any
|
|
148
|
+
if (cleanedValues.length > 0) {
|
|
149
|
+
result.selectedValues = args.allowMultiple ? cleanedValues : cleanedValues[0];
|
|
150
|
+
}
|
|
151
|
+
// Include context if provided
|
|
152
|
+
if (response.otherText && response.otherText !== '') {
|
|
153
|
+
result.context = response.otherText;
|
|
154
|
+
}
|
|
155
|
+
// Determine response type
|
|
156
|
+
if (cleanedValues.length > 0 && result.context) {
|
|
157
|
+
result.responseType = 'selection_with_context';
|
|
158
|
+
}
|
|
159
|
+
else if (cleanedValues.length > 0) {
|
|
160
|
+
result.responseType = 'selection';
|
|
161
|
+
}
|
|
162
|
+
else if (result.context) {
|
|
163
|
+
result.responseType = 'context_only';
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
result.responseType = 'none';
|
|
167
|
+
}
|
|
141
168
|
}
|
|
142
169
|
return {
|
|
143
170
|
content: [
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACtB,SAAS,EACT,QAAQ,EACT,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAgB,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AAEpC,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,cAAc,GAAG,OAAO,CAAC;AAE/B,MAAM,oBAAoB;IAChB,MAAM,CAAS;IACf,aAAa,CAAgB;IAErC;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CACtB;YACE,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,cAAc;SACxB,EACD;YACE,YAAY,EAAE;gBACZ,KAAK,EAAE,EAAE;aACV;SACF,CACF,CAAC;QAEF,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;QACzC,IAAI,CAAC,aAAa,EAAE,CAAC;IACvB,CAAC;IAEO,aAAa;QACnB,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC;YACjE,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC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AC,kBAAkB,CAAC,CAAC;QAClC,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;IACnC,CAAC;CACF;AAED,MAAM,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;AAC1C,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IAC3B,OAAO,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/dist/test-client.js
CHANGED
|
@@ -29,7 +29,21 @@ async function testDialogManager() {
|
|
|
29
29
|
],
|
|
30
30
|
allowMultiple: false,
|
|
31
31
|
allowOther: true,
|
|
32
|
-
context:
|
|
32
|
+
context: `This is for a new web application with expected **10k daily active users**.
|
|
33
|
+
|
|
34
|
+
**Requirements:**
|
|
35
|
+
- Must support \`refresh tokens\`
|
|
36
|
+
- Should integrate with existing \`Redis\` cache
|
|
37
|
+
- Need to handle \`multi-device\` sessions
|
|
38
|
+
|
|
39
|
+
> **Note:** Security is critical - use industry standard practices.
|
|
40
|
+
|
|
41
|
+
\`\`\`javascript
|
|
42
|
+
// Example usage
|
|
43
|
+
const token = generateToken(user);
|
|
44
|
+
\`\`\`
|
|
45
|
+
|
|
46
|
+
See [OAuth 2.0 Spec](https://oauth.net/2/) for details.`
|
|
33
47
|
}
|
|
34
48
|
},
|
|
35
49
|
{
|
package/dist/test-client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-client.js","sourceRoot":"","sources":["../src/test-client.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,KAAK,UAAU,iBAAiB;IAC9B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IAEjD,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IACpC,MAAM,OAAO,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AAQ,EAAE,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;QAE5C,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC5D,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QACvE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QAC1E,CAAC;QAED,2BAA2B;QAC3B,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACjE,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACtB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,eAAe;AACf,iBAAiB,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IAChC,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-dialog-manager.d.ts","sourceRoot":"","sources":["../src/test-dialog-manager.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Simple test to verify the dialog manager works
|
|
2
|
+
import { DialogManager } from './dialog-manager.js';
|
|
3
|
+
async function runTests() {
|
|
4
|
+
console.log('Starting DialogManager tests...\n');
|
|
5
|
+
const manager = new DialogManager();
|
|
6
|
+
let testsPassed = 0;
|
|
7
|
+
let testsFailed = 0;
|
|
8
|
+
// Test 1: Initialization
|
|
9
|
+
try {
|
|
10
|
+
const port = await manager.initialize();
|
|
11
|
+
console.log('✓ Test 1 - Initialization: Server started on port', port);
|
|
12
|
+
testsPassed++;
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
console.error('✗ Test 1 - Initialization failed:', error);
|
|
16
|
+
testsFailed++;
|
|
17
|
+
}
|
|
18
|
+
// Test 2: HTML generation with XSS protection
|
|
19
|
+
try {
|
|
20
|
+
const html = manager.generateDialogHTML({
|
|
21
|
+
id: 'test',
|
|
22
|
+
question: '<script>alert("XSS")</script>',
|
|
23
|
+
options: [
|
|
24
|
+
{
|
|
25
|
+
label: '<b>Bold</b>',
|
|
26
|
+
value: 'test',
|
|
27
|
+
description: '"Quotes" & \'apostrophes\''
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
allowMultiple: false,
|
|
31
|
+
allowOther: true
|
|
32
|
+
});
|
|
33
|
+
if (html.includes('<script>alert') || html.includes('<b>Bold</b>')) {
|
|
34
|
+
throw new Error('XSS protection failed');
|
|
35
|
+
}
|
|
36
|
+
if (!html.includes('<script>') || !html.includes('<b>')) {
|
|
37
|
+
throw new Error('HTML should be escaped');
|
|
38
|
+
}
|
|
39
|
+
console.log('✓ Test 2 - XSS Protection: HTML properly escaped');
|
|
40
|
+
testsPassed++;
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('✗ Test 2 - XSS Protection failed:', error);
|
|
44
|
+
testsFailed++;
|
|
45
|
+
}
|
|
46
|
+
// Test 3: Radio vs Checkbox rendering
|
|
47
|
+
try {
|
|
48
|
+
const radioHtml = manager.generateDialogHTML({
|
|
49
|
+
id: 'test',
|
|
50
|
+
question: 'Choose one',
|
|
51
|
+
options: [
|
|
52
|
+
{ label: 'A', value: 'a' },
|
|
53
|
+
{ label: 'B', value: 'b' }
|
|
54
|
+
],
|
|
55
|
+
allowMultiple: false,
|
|
56
|
+
allowOther: false
|
|
57
|
+
});
|
|
58
|
+
const checkboxHtml = manager.generateDialogHTML({
|
|
59
|
+
id: 'test',
|
|
60
|
+
question: 'Choose many',
|
|
61
|
+
options: [
|
|
62
|
+
{ label: 'A', value: 'a' },
|
|
63
|
+
{ label: 'B', value: 'b' }
|
|
64
|
+
],
|
|
65
|
+
allowMultiple: true,
|
|
66
|
+
allowOther: false
|
|
67
|
+
});
|
|
68
|
+
if (!radioHtml.includes('type="radio"') || radioHtml.includes('type="checkbox"')) {
|
|
69
|
+
throw new Error('Single choice should use radio buttons');
|
|
70
|
+
}
|
|
71
|
+
if (!checkboxHtml.includes('type="checkbox"') || checkboxHtml.includes('type="radio"')) {
|
|
72
|
+
throw new Error('Multiple choice should use checkboxes');
|
|
73
|
+
}
|
|
74
|
+
console.log('✓ Test 3 - Input Types: Correct radio/checkbox rendering');
|
|
75
|
+
testsPassed++;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
console.error('✗ Test 3 - Input Types failed:', error);
|
|
79
|
+
testsFailed++;
|
|
80
|
+
}
|
|
81
|
+
// Test 4: Other field inclusion
|
|
82
|
+
try {
|
|
83
|
+
const withOther = manager.generateDialogHTML({
|
|
84
|
+
id: 'test',
|
|
85
|
+
question: 'Choose',
|
|
86
|
+
options: [{ label: 'A', value: 'a' }],
|
|
87
|
+
allowMultiple: false,
|
|
88
|
+
allowOther: true
|
|
89
|
+
});
|
|
90
|
+
const withoutOther = manager.generateDialogHTML({
|
|
91
|
+
id: 'test',
|
|
92
|
+
question: 'Choose',
|
|
93
|
+
options: [{ label: 'A', value: 'a' }],
|
|
94
|
+
allowMultiple: false,
|
|
95
|
+
allowOther: false
|
|
96
|
+
});
|
|
97
|
+
if (!withOther.includes('other-input')) {
|
|
98
|
+
throw new Error('Should include other field when allowed');
|
|
99
|
+
}
|
|
100
|
+
if (withoutOther.includes('Other (please specify)')) {
|
|
101
|
+
throw new Error('Should not include other field when not allowed');
|
|
102
|
+
}
|
|
103
|
+
console.log('✓ Test 4 - Other Field: Correctly included/excluded');
|
|
104
|
+
testsPassed++;
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error('✗ Test 4 - Other Field failed:', error);
|
|
108
|
+
testsFailed++;
|
|
109
|
+
}
|
|
110
|
+
// Test 5: Context inclusion
|
|
111
|
+
try {
|
|
112
|
+
const withContext = manager.generateDialogHTML({
|
|
113
|
+
id: 'test',
|
|
114
|
+
question: 'Test question',
|
|
115
|
+
options: [{ label: 'Option 1', value: 'opt1' }],
|
|
116
|
+
allowMultiple: false,
|
|
117
|
+
allowOther: false,
|
|
118
|
+
context: 'Important context information'
|
|
119
|
+
});
|
|
120
|
+
const withoutContext = manager.generateDialogHTML({
|
|
121
|
+
id: 'test',
|
|
122
|
+
question: 'Test question',
|
|
123
|
+
options: [{ label: 'Option 1', value: 'opt1' }],
|
|
124
|
+
allowMultiple: false,
|
|
125
|
+
allowOther: false
|
|
126
|
+
});
|
|
127
|
+
if (!withContext.includes('Important context information')) {
|
|
128
|
+
throw new Error('Should include context when provided');
|
|
129
|
+
}
|
|
130
|
+
if (withoutContext.includes('Context:')) {
|
|
131
|
+
throw new Error('Should not include context section when not provided');
|
|
132
|
+
}
|
|
133
|
+
console.log('✓ Test 5 - Context: Correctly included/excluded');
|
|
134
|
+
testsPassed++;
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error('✗ Test 5 - Context failed:', error);
|
|
138
|
+
testsFailed++;
|
|
139
|
+
}
|
|
140
|
+
// Cleanup
|
|
141
|
+
await manager.close();
|
|
142
|
+
// Summary
|
|
143
|
+
console.log(`\n========== Test Summary ==========`);
|
|
144
|
+
console.log(`Passed: ${testsPassed}`);
|
|
145
|
+
console.log(`Failed: ${testsFailed}`);
|
|
146
|
+
console.log(`Total: ${testsPassed + testsFailed}`);
|
|
147
|
+
if (testsFailed > 0) {
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Run tests
|
|
152
|
+
runTests().catch(error => {
|
|
153
|
+
console.error('Test suite failed:', error);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
});
|
|
156
|
+
//# sourceMappingURL=test-dialog-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-dialog-manager.js","sourceRoot":"","sources":["../src/test-dialog-manager.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,KAAK,UAAU,QAAQ;IACrB,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IAEjD,MAAM,OAAO,GAAG,IAAI,aAAa,EAAE,CAAC;IACpC,IAAI,WAAW,GAAG,CAAC,CAAC;IACpB,IAAI,WAAW,GAAG,CAAC,CAAC;IAEpB,yBAAyB;IACzB,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,mDAAmD,EAAE,IAAI,CAAC,CAAC;QACvE,WAAW,EAAE,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,KAAK,CAAC,CAAC;QAC1D,WAAW,EAAE,CAAC;IAChB,CAAC;IAED,8CAA8C;IAC9C,IAAI,CAAC;QACH,MAAM,IAAI,GAAI,OAAe,CAAC,kBAAkB,CAAC;YAC/C,EAAE,EAAE,MAAM;YACV,QAAQ,EAAE,+BAA+B;YACzC,OAAO,EAAE;gBACP;oBACE,KAAK,EAAE,aAAa;oBACpB,KAAK,EAAE,MAAM;oBACb,WAAW,EAAE,4BAA4B;iBAC1C;aACF;YACD,aAAa,EAAE,KAAK;YACpB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAC;QAEH,IAAI,IAAI,CA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QACf,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAC;QACnD,WAAW,EAAE,CAAC;IAChB,CAAC;IAED,UAAU;IACV,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IAEtB,UAAU;IACV,OAAO,CAAC,GAAG,CAAC,sCAAsC,CAAC,CAAC;IACpD,OAAO,CAAC,GAAG,CAAC,WAAW,WAAW,EAAE,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,WAAW,WAAW,EAAE,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,WAAW,WAAW,GAAG,WAAW,EAAE,CAAC,CAAC;IAEpD,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,YAAY;AACZ,QAAQ,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACvB,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@achieveai/hitl-mcp-server",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Human In The Loop MCP Server - Enables LLM agents to ask questions and get user feedback through interactive dialogs",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"files": [
|
|
11
11
|
"dist/",
|
|
12
12
|
"config/",
|
|
13
|
+
"sounds/",
|
|
13
14
|
"mcp.json",
|
|
14
15
|
"README.md",
|
|
15
16
|
"LICENSE",
|
|
Binary file
|