@newsails/veil-cli 1.0.1
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/.veil/agents/analyst/AGENT.md +21 -0
- package/.veil/agents/analyst/agent.json +23 -0
- package/.veil/agents/assistant/AGENT.md +15 -0
- package/.veil/agents/assistant/agent.json +19 -0
- package/.veil/agents/coder/AGENT.md +18 -0
- package/.veil/agents/coder/agent.json +19 -0
- package/.veil/agents/hello/AGENT.md +5 -0
- package/.veil/agents/hello/agent.json +13 -0
- package/.veil/agents/writer/AGENT.md +12 -0
- package/.veil/agents/writer/agent.json +17 -0
- package/.veil/memory/MEMORY.md +343 -0
- package/.veil/memory/agents/analyst/MEMORY.md +55 -0
- package/.veil/memory/agents/hello/MEMORY.md +12 -0
- package/.veil/runtime.pid +1 -0
- package/.veil/settings.json +10 -0
- package/.veil-studio/studio.db +0 -0
- package/.veil-studio/studio.db-shm +0 -0
- package/.veil-studio/studio.db-wal +0 -0
- package/PLAN/01-vision.md +26 -0
- package/PLAN/02-tech-stack.md +94 -0
- package/PLAN/03-agents.md +232 -0
- package/PLAN/04-runtime.md +171 -0
- package/PLAN/05-tools.md +211 -0
- package/PLAN/06-communication.md +243 -0
- package/PLAN/07-storage.md +218 -0
- package/PLAN/08-api-cli.md +153 -0
- package/PLAN/09-permissions.md +108 -0
- package/PLAN/10-ably.md +105 -0
- package/PLAN/11-file-formats.md +442 -0
- package/PLAN/12-folder-structure.md +205 -0
- package/PLAN/13-operations.md +212 -0
- package/PLAN/README.md +23 -0
- package/README.md +128 -0
- package/REPORT.md +174 -0
- package/TODO.md +45 -0
- package/ai-tests/FRONTEND_PROMPT.md +220 -0
- package/ai-tests/Research & Planning.md +814 -0
- package/ai-tests/prompt-001-basic-api.md +230 -0
- package/ai-tests/prompt-002-basic-flows.md +230 -0
- package/ai-tests/prompt-003-agent-behaviors.md +220 -0
- package/api/middleware.js +60 -0
- package/api/routes/agents.js +193 -0
- package/api/routes/chat.js +93 -0
- package/api/routes/completions.js +122 -0
- package/api/routes/daemons.js +80 -0
- package/api/routes/memory.js +169 -0
- package/api/routes/models.js +40 -0
- package/api/routes/remote-methods.js +74 -0
- package/api/routes/sessions.js +208 -0
- package/api/routes/settings.js +108 -0
- package/api/routes/system.js +50 -0
- package/api/routes/tasks.js +270 -0
- package/api/server.js +120 -0
- package/cli/formatter.js +70 -0
- package/cli/index.js +443 -0
- package/cli/parser.js +113 -0
- package/config/config.json +10 -0
- package/config/models.json +6826 -0
- package/core/agent.js +329 -0
- package/core/cancel.js +38 -0
- package/core/compaction.js +176 -0
- package/core/events.js +13 -0
- package/core/loop.js +564 -0
- package/core/memory.js +51 -0
- package/core/prompt.js +185 -0
- package/core/queue.js +96 -0
- package/core/registry.js +291 -0
- package/core/remote-methods.js +124 -0
- package/core/router.js +386 -0
- package/core/running-sessions.js +18 -0
- package/docs/api/01-system.md +84 -0
- package/docs/api/02-agents.md +374 -0
- package/docs/api/03-chat.md +269 -0
- package/docs/api/04-tasks.md +470 -0
- package/docs/api/05-sessions.md +444 -0
- package/docs/api/06-daemons.md +142 -0
- package/docs/api/07-memory.md +186 -0
- package/docs/api/08-settings.md +133 -0
- package/docs/api/09-models.md +119 -0
- package/docs/api/09-websocket.md +350 -0
- package/docs/api/10-completions.md +134 -0
- package/docs/api/README.md +116 -0
- package/docs/guide/01-quickstart.md +220 -0
- package/docs/guide/02-folder-structure.md +185 -0
- package/docs/guide/03-configuration.md +252 -0
- package/docs/guide/04-agents.md +267 -0
- package/docs/guide/05-cli.md +290 -0
- package/docs/guide/06-tools.md +643 -0
- package/docs/guide/07-permissions.md +236 -0
- package/docs/guide/08-memory.md +139 -0
- package/docs/guide/09-multi-agent.md +271 -0
- package/docs/guide/10-daemons.md +226 -0
- package/docs/guide/README.md +53 -0
- package/docs/index.html +623 -0
- package/examples/README.md +151 -0
- package/examples/agents/assistant/AGENT.md +31 -0
- package/examples/agents/assistant/SOUL.md +9 -0
- package/examples/agents/assistant/agent.json +74 -0
- package/examples/agents/hello/AGENT.md +15 -0
- package/examples/agents/hello/agent.json +14 -0
- package/examples/agents/monitor/AGENT.md +51 -0
- package/examples/agents/monitor/agent.json +33 -0
- package/examples/agents/monitor/heartbeats/monitor.md +24 -0
- package/examples/agents/orchestrator/AGENT.md +70 -0
- package/examples/agents/orchestrator/agent.json +30 -0
- package/examples/agents/researcher/AGENT.md +52 -0
- package/examples/agents/researcher/agent.json +49 -0
- package/examples/agents/researcher/skills/web-research.md +28 -0
- package/examples/skills/code-review.md +72 -0
- package/examples/skills/summarise.md +59 -0
- package/examples/skills/web-research.md +42 -0
- package/examples/tools/word-count/index.js +27 -0
- package/examples/tools/word-count/tool.json +18 -0
- package/infrastructure/database.js +563 -0
- package/infrastructure/scheduler.js +122 -0
- package/llm/client.js +206 -0
- package/migrations/001-initial.sql +121 -0
- package/migrations/002-debuggability.sql +13 -0
- package/migrations/003-drop-orphaned-columns.sql +72 -0
- package/migrations/004-session-message-token-fields.sql +78 -0
- package/migrations/005-session-thinking.sql +5 -0
- package/package.json +30 -0
- package/schemas/agent.json +143 -0
- package/schemas/settings.json +111 -0
- package/scripts/fetch-models.js +93 -0
- package/session-debug-scenario.md +248 -0
- package/settings/fields.js +52 -0
- package/system-prompts/base-core.md +7 -0
- package/system-prompts/environment.md +13 -0
- package/system-prompts/reminders/anti-drift.md +6 -0
- package/system-prompts/reminders/stall-recovery.md +10 -0
- package/system-prompts/safety-rules.md +25 -0
- package/system-prompts/task-heuristics.md +27 -0
- package/test/client.js +71 -0
- package/test/integration/01-health.test.js +25 -0
- package/test/integration/02-agents.test.js +80 -0
- package/test/integration/03-chat-hello.test.js +48 -0
- package/test/integration/04-chat-multiturn.test.js +61 -0
- package/test/integration/05-chat-writer.test.js +48 -0
- package/test/integration/06-task-basic.test.js +68 -0
- package/test/integration/07-task-tools.test.js +74 -0
- package/test/integration/08-task-code-analysis.test.js +69 -0
- package/test/integration/09-memory-analyst.test.js +63 -0
- package/test/integration/10-task-advanced.test.js +85 -0
- package/test/integration/11-sessions-advanced.test.js +84 -0
- package/test/integration/12-assistant-chat-tools.test.js +75 -0
- package/test/integration/13-edge-cases.test.js +99 -0
- package/test/integration/14-cancel.test.js +62 -0
- package/test/integration/15-debug.test.js +106 -0
- package/test/integration/16-memory-api.test.js +83 -0
- package/test/integration/17-settings-api.test.js +41 -0
- package/test/integration/18-tool-search-activation.test.js +119 -0
- package/test/results/.gitkeep +0 -0
- package/test/runner.js +206 -0
- package/test/smoke.js +216 -0
- package/tools/agent_message.js +85 -0
- package/tools/agent_send.js +80 -0
- package/tools/agent_spawn.js +44 -0
- package/tools/bash.js +49 -0
- package/tools/edit_file.js +41 -0
- package/tools/glob.js +64 -0
- package/tools/grep.js +82 -0
- package/tools/list_dir.js +63 -0
- package/tools/log_write.js +31 -0
- package/tools/memory_read.js +38 -0
- package/tools/memory_search.js +65 -0
- package/tools/memory_write.js +42 -0
- package/tools/read_file.js +48 -0
- package/tools/sleep.js +22 -0
- package/tools/task_create.js +41 -0
- package/tools/task_respond.js +37 -0
- package/tools/task_spawn.js +64 -0
- package/tools/task_status.js +39 -0
- package/tools/task_subscribe.js +37 -0
- package/tools/todo_read.js +26 -0
- package/tools/todo_write.js +38 -0
- package/tools/tool_activate.js +24 -0
- package/tools/tool_search.js +24 -0
- package/tools/web_fetch.js +50 -0
- package/tools/web_search.js +52 -0
- package/tools/write_file.js +28 -0
- package/ui/api.js +190 -0
- package/ui/app.js +281 -0
- package/ui/index.html +382 -0
- package/ui/views/agents.js +377 -0
- package/ui/views/chat.js +610 -0
- package/ui/views/connection.js +96 -0
- package/ui/views/daemons.js +129 -0
- package/ui/views/feed.js +194 -0
- package/ui/views/memory.js +263 -0
- package/ui/views/models.js +146 -0
- package/ui/views/sessions.js +314 -0
- package/ui/views/settings.js +142 -0
- package/ui/views/tasks.js +415 -0
- package/utils/context.js +49 -0
- package/utils/id.js +16 -0
- package/utils/models.js +88 -0
- package/utils/paths.js +213 -0
- package/utils/settings.js +172 -0
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
# Sessions
|
|
2
|
+
|
|
3
|
+
A session is created automatically for every chat or task run. It holds the full conversation history (system prompt, user messages, assistant replies, tool calls, tool results).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## POST /sessions
|
|
8
|
+
|
|
9
|
+
Create a new session without sending a message. Useful when you want to pre-create a session and pass it as `sessionId` to the chat endpoint, or to attach a stream listener before the first message.
|
|
10
|
+
|
|
11
|
+
A system prompt is automatically injected as the first message.
|
|
12
|
+
|
|
13
|
+
**Request body**
|
|
14
|
+
|
|
15
|
+
| Field | Type | Required | Description |
|
|
16
|
+
|-------|------|----------|-------------|
|
|
17
|
+
| `agentName` | string | ✓ | Agent to create the session for |
|
|
18
|
+
| `mode` | string | | `chat` (default), `task`, `daemon`, or `subagent` |
|
|
19
|
+
| `model` | string | | Override model for this session. Defaults to the agent's configured model. |
|
|
20
|
+
| `model_thinking` | object\|null | | Extended thinking config for this session, e.g. `{"type":"enabled","budget_tokens":5000}`. Defaults to agent's `thinking` config if set. Pass `null` to disable. |
|
|
21
|
+
|
|
22
|
+
**Request example**
|
|
23
|
+
```json
|
|
24
|
+
{
|
|
25
|
+
"agentName": "assistant",
|
|
26
|
+
"mode": "chat"
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**Response** `201 Created`
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"sessionId": "sess_4f3a1b9c2d8e7f01",
|
|
34
|
+
"session": {
|
|
35
|
+
"id": "sess_4f3a1b9c2d8e7f01",
|
|
36
|
+
"agent_name": "assistant",
|
|
37
|
+
"mode": "chat",
|
|
38
|
+
"status": "active",
|
|
39
|
+
"model": "anthropic/claude-sonnet-4-5",
|
|
40
|
+
"created_at": "2025-03-02T10:00:00.000Z",
|
|
41
|
+
"updated_at": "2025-03-02T10:00:00.000Z"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Error responses**
|
|
47
|
+
|
|
48
|
+
| Code | Condition |
|
|
49
|
+
|------|-----------|
|
|
50
|
+
| `404 AGENT_NOT_FOUND` | No agent with that name |
|
|
51
|
+
| `400 VALIDATION_ERROR` | `agentName` missing or `mode` is invalid |
|
|
52
|
+
|
|
53
|
+
**Example**
|
|
54
|
+
```bash
|
|
55
|
+
curl -X POST http://localhost:5050/sessions \
|
|
56
|
+
-H "Content-Type: application/json" \
|
|
57
|
+
-d '{"agentName": "assistant", "mode": "chat"}'
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## GET /sessions
|
|
63
|
+
|
|
64
|
+
List sessions for the current workspace.
|
|
65
|
+
|
|
66
|
+
**Query parameters**
|
|
67
|
+
|
|
68
|
+
| Param | Type | Description |
|
|
69
|
+
|-------|------|-------------|
|
|
70
|
+
| `agentName` | string | Filter by agent name |
|
|
71
|
+
| `status` | string | `active` or `closed` |
|
|
72
|
+
| `limit` | integer | Max results (default: 20) |
|
|
73
|
+
| `cursor` | string | Pagination cursor (last session ID from previous page) |
|
|
74
|
+
|
|
75
|
+
**Response**
|
|
76
|
+
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"sessions": [
|
|
80
|
+
{
|
|
81
|
+
"id": "sess_4f3a1b9c2d8e7f01",
|
|
82
|
+
"agent_name": "assistant",
|
|
83
|
+
"mode": "chat",
|
|
84
|
+
"status": "active",
|
|
85
|
+
"model": "moonshotai/kimi-k2.5",
|
|
86
|
+
"message_count": 6,
|
|
87
|
+
"instance_folder": "/home/user/workspace",
|
|
88
|
+
"created_at": "2025-03-02T10:00:00.000Z",
|
|
89
|
+
"updated_at": "2025-03-02T10:05:00.000Z"
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Session object fields**
|
|
96
|
+
|
|
97
|
+
| Field | Type | Description |
|
|
98
|
+
|-------|------|-------------|
|
|
99
|
+
| `id` | string | Unique session ID |
|
|
100
|
+
| `agent_name` | string | Agent this session belongs to |
|
|
101
|
+
| `mode` | string | `chat`, `task`, `daemon`, or `subagent` |
|
|
102
|
+
| `status` | string | `active` or `closed` |
|
|
103
|
+
| `model` | string | LLM model used |
|
|
104
|
+
| `title` | string\|null | Optional session title |
|
|
105
|
+
| `message_count` | integer | Total messages in this session |
|
|
106
|
+
| `total_input_tokens` | integer | Accumulated prompt tokens for the session (includes deleted messages and resets) |
|
|
107
|
+
| `total_output_tokens` | integer | Accumulated completion tokens for the session |
|
|
108
|
+
| `total_cache_tokens` | integer | Accumulated cached prompt tokens for the session |
|
|
109
|
+
| `context_size` | integer | Prompt + completion tokens of the **last** LLM turn (current context window usage) |
|
|
110
|
+
| `context_size_limit` | integer\|null | Model context limit in tokens (if known) |
|
|
111
|
+
| `cost` | number | Accumulated cost in USD for the session |
|
|
112
|
+
| `model_thinking` | object\|null | Extended thinking config active for this session (JSON-encoded in DB, returned as object) |
|
|
113
|
+
| `instance_folder` | string | Workspace that owns this session |
|
|
114
|
+
| `created_at` | ISO string | When session was created |
|
|
115
|
+
| `updated_at` | ISO string | Last activity timestamp |
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## GET /sessions/:id
|
|
120
|
+
|
|
121
|
+
Get details for a single session.
|
|
122
|
+
|
|
123
|
+
**Path parameters**
|
|
124
|
+
|
|
125
|
+
| Param | Description |
|
|
126
|
+
|-------|-------------|
|
|
127
|
+
| `id` | Session ID |
|
|
128
|
+
|
|
129
|
+
**Response**
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"session": {
|
|
134
|
+
"id": "sess_4f3a1b9c2d8e7f01",
|
|
135
|
+
"agent_name": "assistant",
|
|
136
|
+
"mode": "chat",
|
|
137
|
+
"status": "active",
|
|
138
|
+
"model": "moonshotai/kimi-k2.5",
|
|
139
|
+
"message_count": 6,
|
|
140
|
+
"instance_folder": "/home/user/workspace",
|
|
141
|
+
"created_at": "2025-03-02T10:00:00.000Z",
|
|
142
|
+
"updated_at": "2025-03-02T10:05:00.000Z"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**Error responses**
|
|
148
|
+
|
|
149
|
+
| Code | Condition |
|
|
150
|
+
|------|-----------|
|
|
151
|
+
| `404 SESSION_NOT_FOUND` | No session with that ID |
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## GET /sessions/:id/messages
|
|
156
|
+
|
|
157
|
+
Retrieve the message history for a session.
|
|
158
|
+
|
|
159
|
+
**Path parameters**
|
|
160
|
+
|
|
161
|
+
| Param | Description |
|
|
162
|
+
|-------|-------------|
|
|
163
|
+
| `id` | Session ID |
|
|
164
|
+
|
|
165
|
+
**Query parameters**
|
|
166
|
+
|
|
167
|
+
| Param | Type | Description |
|
|
168
|
+
|-------|------|-------------|
|
|
169
|
+
| `limit` | integer | Max messages to return (default: 100) |
|
|
170
|
+
| `offset` | integer | Skip first N messages (default: 0) |
|
|
171
|
+
|
|
172
|
+
**Response**
|
|
173
|
+
|
|
174
|
+
```json
|
|
175
|
+
{
|
|
176
|
+
"sessionId": "sess_4f3a1b9c2d8e7f01",
|
|
177
|
+
"messages": [
|
|
178
|
+
{
|
|
179
|
+
"id": 1,
|
|
180
|
+
"session_id": "sess_4f3a1b9c2d8e7f01",
|
|
181
|
+
"role": "system",
|
|
182
|
+
"content": "You are Assistant, a helpful agent...",
|
|
183
|
+
"tool_calls": null,
|
|
184
|
+
"tool_call_id": null,
|
|
185
|
+
"created_at": "2025-03-02T10:00:00.000Z"
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"id": 2,
|
|
189
|
+
"role": "user",
|
|
190
|
+
"content": "What files are in the current directory?",
|
|
191
|
+
"tool_calls": null,
|
|
192
|
+
"tool_call_id": null,
|
|
193
|
+
"created_at": "2025-03-02T10:00:01.000Z"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"id": 3,
|
|
197
|
+
"role": "assistant",
|
|
198
|
+
"content": null,
|
|
199
|
+
"tool_calls": "[{\"id\":\"call_abc\",\"type\":\"function\",\"function\":{\"name\":\"list_dir\",\"arguments\":\"{\\\"dir\\\":\\\".\\\"}\"}}]",
|
|
200
|
+
"tool_call_id": null,
|
|
201
|
+
"created_at": "2025-03-02T10:00:02.000Z"
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
"id": 4,
|
|
205
|
+
"role": "tool",
|
|
206
|
+
"content": "README.md (1.2KB)\npackage.json (544B)\n...",
|
|
207
|
+
"tool_calls": null,
|
|
208
|
+
"tool_call_id": "call_abc",
|
|
209
|
+
"created_at": "2025-03-02T10:00:03.000Z"
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
"id": 5,
|
|
213
|
+
"role": "assistant",
|
|
214
|
+
"content": "Here are the files in the current directory:\n- README.md\n- package.json",
|
|
215
|
+
"tool_calls": null,
|
|
216
|
+
"tool_call_id": null,
|
|
217
|
+
"created_at": "2025-03-02T10:00:04.000Z"
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Message object fields**
|
|
224
|
+
|
|
225
|
+
| Field | Type | Description |
|
|
226
|
+
|-------|------|-------------|
|
|
227
|
+
| `id` | integer | Auto-incremented message ID |
|
|
228
|
+
| `session_id` | string | Parent session |
|
|
229
|
+
| `role` | string | `system`, `user`, `assistant`, or `tool` |
|
|
230
|
+
| `content` | string\|null | Text content (null for tool-call-only assistant messages) |
|
|
231
|
+
| `tool_calls` | array\|null | OpenAI tool call objects (parsed from JSON) — present on `assistant` messages that call tools |
|
|
232
|
+
| `tool_call_id` | string\|null | Links a `tool` result back to the originating tool call |
|
|
233
|
+
| `model_key` | string\|null | Model used for this message (only set on `assistant` messages) |
|
|
234
|
+
| `input_tokens` | integer\|null | Prompt tokens for this LLM call (assistant messages only) |
|
|
235
|
+
| `output_tokens` | integer\|null | Completion tokens for this LLM call (assistant messages only) |
|
|
236
|
+
| `cache_tokens` | integer\|null | Cached prompt tokens for this LLM call (assistant messages only) |
|
|
237
|
+
| `cost` | number\|null | Cost in USD for this LLM call — from API response, null if not reported |
|
|
238
|
+
| `created_at` | ISO string | When the message was created |
|
|
239
|
+
|
|
240
|
+
**Message roles**
|
|
241
|
+
|
|
242
|
+
| Role | Description |
|
|
243
|
+
|------|-------------|
|
|
244
|
+
| `system` | System prompt (first message, set once per session) |
|
|
245
|
+
| `user` | User input message |
|
|
246
|
+
| `assistant` | Agent reply — may have `tool_calls` instead of `content` when using tools |
|
|
247
|
+
| `tool` | Tool execution result — `tool_call_id` links it to the assistant's tool call |
|
|
248
|
+
|
|
249
|
+
**Note on `tool_calls`**: The field is a JSON string (not a nested object) containing an array of OpenAI function-call objects. Parse it with `JSON.parse()`.
|
|
250
|
+
|
|
251
|
+
**Error responses**
|
|
252
|
+
|
|
253
|
+
| Code | Condition |
|
|
254
|
+
|------|-----------|
|
|
255
|
+
| `404 SESSION_NOT_FOUND` | No session with that ID |
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## GET /sessions/:id/stream
|
|
260
|
+
|
|
261
|
+
Real-time SSE (Server-Sent Events) stream for a session. Streams all runtime events scoped to this session — tool calls, LLM responses, iteration starts, daemon ticks, and more.
|
|
262
|
+
|
|
263
|
+
**Path parameters**
|
|
264
|
+
|
|
265
|
+
| Param | Description |
|
|
266
|
+
|-------|-------------|
|
|
267
|
+
| `id` | Session ID |
|
|
268
|
+
|
|
269
|
+
**Response** — `text/event-stream`
|
|
270
|
+
|
|
271
|
+
The stream opens with a `session` event showing the current session state, then forwards all matching eventBus events in real time.
|
|
272
|
+
|
|
273
|
+
**`event: session`** — sent immediately on connection:
|
|
274
|
+
```
|
|
275
|
+
event: session
|
|
276
|
+
data: {"sessionId":"sess_...","status":"active","agentName":"assistant","mode":"chat"}
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
**Live events** — one SSE event per bus event, named by event type:
|
|
280
|
+
```
|
|
281
|
+
event: chat.tool
|
|
282
|
+
data: {"sessionId":"sess_...","agentName":"assistant","event":{"type":"tool.start","toolName":"read_file","toolInput":{"path":"package.json"}},"timestamp":1234567890}
|
|
283
|
+
|
|
284
|
+
event: chat.response
|
|
285
|
+
data: {"sessionId":"sess_...","agentName":"assistant","event":{"content":"Here are the files...","toolCount":2},"timestamp":1234567890}
|
|
286
|
+
|
|
287
|
+
event: chat.event
|
|
288
|
+
data: {"sessionId":"sess_...","agentName":"assistant","event":{"type":"iteration.start","iteration":1},"timestamp":1234567890}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
**Event types by session mode**
|
|
292
|
+
|
|
293
|
+
| Type | Mode | Description |
|
|
294
|
+
|------|------|-------------|
|
|
295
|
+
| `chat.event` | chat | Iteration start, LLM errors |
|
|
296
|
+
| `chat.tool` | chat | Tool call start/end |
|
|
297
|
+
| `chat.response` | chat | Final agent reply |
|
|
298
|
+
| `task.event` | task | Tool calls, iteration progress |
|
|
299
|
+
| `task.status` | task | Task status changes (via associated taskId) |
|
|
300
|
+
| `daemon.tick` | daemon | Daemon tick start/done/error |
|
|
301
|
+
|
|
302
|
+
A keepalive comment is sent every 15 seconds:
|
|
303
|
+
```
|
|
304
|
+
: keepalive
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
The stream stays open until the client disconnects. There is no automatic close.
|
|
308
|
+
|
|
309
|
+
**Error responses**
|
|
310
|
+
|
|
311
|
+
| Code | Condition |
|
|
312
|
+
|------|-----------|
|
|
313
|
+
| `404 SESSION_NOT_FOUND` | No session with that ID |
|
|
314
|
+
|
|
315
|
+
**JavaScript example**
|
|
316
|
+
```js
|
|
317
|
+
// Pre-create a session, then open the stream before sending the first message
|
|
318
|
+
const { sessionId } = await fetch('http://localhost:5050/sessions', {
|
|
319
|
+
method: 'POST',
|
|
320
|
+
headers: { 'Content-Type': 'application/json' },
|
|
321
|
+
body: JSON.stringify({ agentName: 'assistant' }),
|
|
322
|
+
}).then(r => r.json());
|
|
323
|
+
|
|
324
|
+
const source = new EventSource(`http://localhost:5050/sessions/${sessionId}/stream`);
|
|
325
|
+
|
|
326
|
+
source.addEventListener('chat.tool', (e) => {
|
|
327
|
+
const { event } = JSON.parse(e.data);
|
|
328
|
+
if (event.type === 'tool.start') console.log('Tool:', event.toolName);
|
|
329
|
+
if (event.type === 'tool.end') console.log('Done in', event.durationMs, 'ms');
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
source.addEventListener('chat.response', (e) => {
|
|
333
|
+
const { event } = JSON.parse(e.data);
|
|
334
|
+
console.log('Reply:', event.content);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
// Now send a chat message using the pre-created sessionId
|
|
338
|
+
await fetch(`http://localhost:5050/agents/assistant/chat`, {
|
|
339
|
+
method: 'POST',
|
|
340
|
+
headers: { 'Content-Type': 'application/json' },
|
|
341
|
+
body: JSON.stringify({ message: 'List files in the current dir', sessionId }),
|
|
342
|
+
});
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
## GET /sessions/:id/context
|
|
348
|
+
|
|
349
|
+
Returns the full message history for debugging. Unlike `/messages`, this endpoint formats messages for quick context inspection.
|
|
350
|
+
|
|
351
|
+
**Response**
|
|
352
|
+
|
|
353
|
+
```json
|
|
354
|
+
{
|
|
355
|
+
"sessionId": "sess_4f3a1b9c2d8e7f01",
|
|
356
|
+
"agentName": "assistant",
|
|
357
|
+
"mode": "chat",
|
|
358
|
+
"messageCount": 5,
|
|
359
|
+
"messages": [
|
|
360
|
+
{ "id": 1, "role": "system", "content": "You are...", "created_at": "..." },
|
|
361
|
+
{ "id": 2, "role": "user", "content": "What files...", "created_at": "..." },
|
|
362
|
+
{ "id": 3, "role": "assistant", "content": null, "tool_calls": [...], "created_at": "..." }
|
|
363
|
+
]
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**Error responses**
|
|
368
|
+
|
|
369
|
+
| Code | Condition |
|
|
370
|
+
|------|-----------|
|
|
371
|
+
| `404 SESSION_NOT_FOUND` | No session with that ID |
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## POST /sessions/:id/reset
|
|
376
|
+
|
|
377
|
+
Clear all messages from a session but keep the session alive. A fresh system prompt is re-injected so the agent starts with a clean slate.
|
|
378
|
+
|
|
379
|
+
**Response**
|
|
380
|
+
|
|
381
|
+
```json
|
|
382
|
+
{
|
|
383
|
+
"sessionId": "sess_4f3a1b9c2d8e7f01",
|
|
384
|
+
"status": "reset",
|
|
385
|
+
"messageCount": 1
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
**Error responses**
|
|
390
|
+
|
|
391
|
+
| Code | Condition |
|
|
392
|
+
|------|-----------|
|
|
393
|
+
| `400 SESSION_CLOSED` | Cannot reset a closed session |
|
|
394
|
+
| `404 SESSION_NOT_FOUND` | No session with that ID |
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## DELETE /sessions/:id
|
|
399
|
+
|
|
400
|
+
Close or delete a session.
|
|
401
|
+
|
|
402
|
+
**Query parameters**
|
|
403
|
+
|
|
404
|
+
| Param | Type | Description |
|
|
405
|
+
|-------|------|-------------|
|
|
406
|
+
| `hard` | string | Set to `"true"` to permanently delete the session and all messages. Default: soft close only. |
|
|
407
|
+
|
|
408
|
+
**Path parameters**
|
|
409
|
+
|
|
410
|
+
| Param | Description |
|
|
411
|
+
|-------|-------------|
|
|
412
|
+
| `id` | Session ID |
|
|
413
|
+
|
|
414
|
+
**Response (soft close — default)**
|
|
415
|
+
|
|
416
|
+
```json
|
|
417
|
+
{
|
|
418
|
+
"sessionId": "sess_4f3a1b9c2d8e7f01",
|
|
419
|
+
"status": "closed"
|
|
420
|
+
}
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
**Response (hard delete — `?hard=true`)**
|
|
424
|
+
|
|
425
|
+
```json
|
|
426
|
+
{
|
|
427
|
+
"sessionId": "sess_4f3a1b9c2d8e7f01",
|
|
428
|
+
"status": "deleted"
|
|
429
|
+
}
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
**Error responses**
|
|
433
|
+
|
|
434
|
+
| Code | Condition |
|
|
435
|
+
|------|-----------|
|
|
436
|
+
| `404 SESSION_NOT_FOUND` | No session with that ID |
|
|
437
|
+
|
|
438
|
+
---
|
|
439
|
+
|
|
440
|
+
## Notes
|
|
441
|
+
|
|
442
|
+
- Sessions are scoped to the workspace (`instance_folder`). You cannot access sessions from a different server instance using the same ID.
|
|
443
|
+
- Task sessions (`mode: "task"`) are created and managed automatically — do not close them manually.
|
|
444
|
+
- Chat sessions (`mode: "chat"`) stay `active` until explicitly closed or the server restarts (active sessions are left open; they can be resumed).
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
# Daemons
|
|
2
|
+
|
|
3
|
+
Daemon agents run on a cron schedule. They wake up, execute their task (reading a heartbeat file for instructions), and go back to sleep. Daemons with a `schedule` in their `agent.json` are auto-started when the server boots.
|
|
4
|
+
|
|
5
|
+
See [Daemon Agents guide](../guide/10-daemons.md) for configuration details.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## GET /daemons
|
|
10
|
+
|
|
11
|
+
List all currently active daemon schedulers.
|
|
12
|
+
|
|
13
|
+
**Response**
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"daemons": [
|
|
18
|
+
{
|
|
19
|
+
"agentName": "monitor",
|
|
20
|
+
"schedule": "*/5 * * * *",
|
|
21
|
+
"status": "active",
|
|
22
|
+
"lastTick": "2025-03-02T10:05:00.000Z",
|
|
23
|
+
"nextTick": "2025-03-02T10:10:00.000Z"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
| Field | Type | Description |
|
|
30
|
+
|-------|------|-------------|
|
|
31
|
+
| `agentName` | string | Agent identifier |
|
|
32
|
+
| `schedule` | string | Cron expression |
|
|
33
|
+
| `status` | string | `active` |
|
|
34
|
+
| `lastTick` | ISO string \| null | When the last tick ran |
|
|
35
|
+
| `nextTick` | ISO string \| null | When the next tick is scheduled |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## POST /agents/:name/daemon/start
|
|
40
|
+
|
|
41
|
+
Start scheduling a daemon agent. The agent must have `modes.daemon.enabled: true` in its `agent.json`.
|
|
42
|
+
|
|
43
|
+
**Path parameters**
|
|
44
|
+
|
|
45
|
+
| Param | Description |
|
|
46
|
+
|-------|-------------|
|
|
47
|
+
| `name` | Agent name |
|
|
48
|
+
|
|
49
|
+
**Request body** — none
|
|
50
|
+
|
|
51
|
+
**Response**
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"agentName": "monitor",
|
|
56
|
+
"status": "started"
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Error responses**
|
|
61
|
+
|
|
62
|
+
| Code | Condition |
|
|
63
|
+
|------|-----------|
|
|
64
|
+
| `400 MODE_NOT_SUPPORTED` | Agent does not have daemon mode enabled |
|
|
65
|
+
| `404 AGENT_NOT_FOUND` | No agent with that name |
|
|
66
|
+
|
|
67
|
+
**Example**
|
|
68
|
+
```bash
|
|
69
|
+
curl -X POST http://localhost:5050/agents/monitor/daemon/start
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## POST /agents/:name/daemon/stop
|
|
75
|
+
|
|
76
|
+
Stop a running daemon scheduler. The agent will not run again until started.
|
|
77
|
+
|
|
78
|
+
**Path parameters**
|
|
79
|
+
|
|
80
|
+
| Param | Description |
|
|
81
|
+
|-------|-------------|
|
|
82
|
+
| `name` | Agent name |
|
|
83
|
+
|
|
84
|
+
**Request body** — none
|
|
85
|
+
|
|
86
|
+
**Response**
|
|
87
|
+
|
|
88
|
+
```json
|
|
89
|
+
{
|
|
90
|
+
"agentName": "monitor",
|
|
91
|
+
"status": "stopped"
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Example**
|
|
96
|
+
```bash
|
|
97
|
+
curl -X POST http://localhost:5050/agents/monitor/daemon/stop
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## POST /agents/:name/daemon/trigger
|
|
103
|
+
|
|
104
|
+
Manually trigger a single daemon tick immediately, regardless of the cron schedule. The tick runs asynchronously — the endpoint returns immediately.
|
|
105
|
+
|
|
106
|
+
**Path parameters**
|
|
107
|
+
|
|
108
|
+
| Param | Description |
|
|
109
|
+
|-------|-------------|
|
|
110
|
+
| `name` | Agent name |
|
|
111
|
+
|
|
112
|
+
**Request body** — none
|
|
113
|
+
|
|
114
|
+
**Response**
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"agentName": "monitor",
|
|
119
|
+
"status": "triggered"
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
**Error responses**
|
|
124
|
+
|
|
125
|
+
| Code | Condition |
|
|
126
|
+
|------|-----------|
|
|
127
|
+
| `400 MODE_NOT_SUPPORTED` | Agent does not have daemon mode enabled |
|
|
128
|
+
| `404 AGENT_NOT_FOUND` | No agent with that name |
|
|
129
|
+
|
|
130
|
+
**Example**
|
|
131
|
+
```bash
|
|
132
|
+
curl -X POST http://localhost:5050/agents/monitor/daemon/trigger
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Notes
|
|
138
|
+
|
|
139
|
+
- **Auto-start**: Daemons with a `schedule` field in `agent.json` start automatically when `veil start` runs.
|
|
140
|
+
- **Conflict policy**: If a tick fires while the previous one is still running, behavior depends on `conflictPolicy` in `agent.json`: `skip` (default), `queue`, or `restart`.
|
|
141
|
+
- **Heartbeat files**: By default the daemon reads `.veil/heartbeats/<agentName>.md` as its instruction. Customize with `heartbeatFile` in `agent.json`.
|
|
142
|
+
- Daemon sessions are created per tick and auto-closed when the tick completes.
|