agent-world 0.12.0 → 0.12.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/README.md +7 -4
- package/bin/agent-world-cli.js +41 -0
- package/bin/agent-world-server.js +40 -0
- package/bin/agent-world.js +53 -0
- package/dist/cli/index.js +4 -4
- package/dist/core/activity-tracker.d.ts +0 -1
- package/dist/core/activity-tracker.js +0 -1
- package/dist/core/anthropic-direct.d.ts +0 -1
- package/dist/core/anthropic-direct.js +0 -1
- package/dist/core/chat-constants.d.ts +0 -1
- package/dist/core/chat-constants.js +0 -1
- package/dist/core/create-agent-tool.d.ts +0 -1
- package/dist/core/create-agent-tool.js +0 -1
- package/dist/core/events/index.d.ts +0 -1
- package/dist/core/events/index.js +0 -1
- package/dist/core/events/memory-manager.d.ts +0 -1
- package/dist/core/events/memory-manager.js +0 -1
- package/dist/core/events/mention-logic.d.ts +0 -1
- package/dist/core/events/mention-logic.js +0 -1
- package/dist/core/events/orchestrator.d.ts +0 -1
- package/dist/core/events/orchestrator.js +0 -1
- package/dist/core/events/persistence.d.ts +0 -1
- package/dist/core/events/persistence.js +0 -1
- package/dist/core/events/publishers.d.ts +0 -1
- package/dist/core/events/publishers.js +0 -1
- package/dist/core/events/subscribers.d.ts +0 -1
- package/dist/core/events/subscribers.js +0 -1
- package/dist/core/events/tool-bridge-logging.d.ts +0 -1
- package/dist/core/events/tool-bridge-logging.js +0 -1
- package/dist/core/events-metadata.d.ts +0 -1
- package/dist/core/events-metadata.js +0 -1
- package/dist/core/export.d.ts +0 -1
- package/dist/core/export.js +0 -1
- package/dist/core/file-tools.d.ts +0 -1
- package/dist/core/file-tools.js +0 -1
- package/dist/core/google-direct.d.ts +0 -1
- package/dist/core/google-direct.js +0 -1
- package/dist/core/hitl.d.ts +0 -1
- package/dist/core/hitl.js +0 -1
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +0 -1
- package/dist/core/llm-config.d.ts +0 -1
- package/dist/core/llm-config.js +0 -1
- package/dist/core/llm-manager.d.ts +0 -1
- package/dist/core/llm-manager.js +0 -1
- package/dist/core/load-skill-tool.d.ts +0 -1
- package/dist/core/load-skill-tool.js +0 -1
- package/dist/core/logger.d.ts +0 -1
- package/dist/core/logger.js +0 -1
- package/dist/core/managers.d.ts +0 -1
- package/dist/core/managers.js +0 -1
- package/dist/core/mcp-server-registry.d.ts +0 -1
- package/dist/core/mcp-server-registry.js +0 -1
- package/dist/core/message-prep.d.ts +0 -1
- package/dist/core/message-prep.js +0 -1
- package/dist/core/message-processing-control.d.ts +0 -1
- package/dist/core/message-processing-control.js +0 -1
- package/dist/core/openai-direct.d.ts +0 -1
- package/dist/core/openai-direct.js +0 -1
- package/dist/core/shell-cmd-tool.d.ts +0 -1
- package/dist/core/shell-cmd-tool.js +0 -1
- package/dist/core/shell-process-registry.d.ts +0 -1
- package/dist/core/shell-process-registry.js +0 -1
- package/dist/core/skill-registry.d.ts +0 -1
- package/dist/core/skill-registry.js +0 -1
- package/dist/core/skill-settings.d.ts +0 -1
- package/dist/core/skill-settings.js +0 -1
- package/dist/core/storage/agent-storage.d.ts +0 -1
- package/dist/core/storage/agent-storage.js +0 -1
- package/dist/core/storage/eventStorage/fileEventStorage.d.ts +0 -1
- package/dist/core/storage/eventStorage/fileEventStorage.js +0 -1
- package/dist/core/storage/eventStorage/index.d.ts +0 -1
- package/dist/core/storage/eventStorage/index.js +0 -1
- package/dist/core/storage/eventStorage/memoryEventStorage.d.ts +0 -1
- package/dist/core/storage/eventStorage/memoryEventStorage.js +0 -1
- package/dist/core/storage/eventStorage/sqliteEventStorage.d.ts +0 -1
- package/dist/core/storage/eventStorage/sqliteEventStorage.js +0 -1
- package/dist/core/storage/eventStorage/types.d.ts +0 -1
- package/dist/core/storage/eventStorage/types.js +0 -1
- package/dist/core/storage/eventStorage/validation.d.ts +0 -1
- package/dist/core/storage/eventStorage/validation.js +0 -1
- package/dist/core/storage/memory-storage.d.ts +0 -1
- package/dist/core/storage/memory-storage.js +0 -1
- package/dist/core/storage/migration-runner.d.ts +0 -1
- package/dist/core/storage/migration-runner.d.ts.map +1 -1
- package/dist/core/storage/migration-runner.js +4 -11
- package/dist/core/storage/migration-runner.js.map +1 -1
- package/dist/core/storage/sqlite-schema.d.ts +0 -1
- package/dist/core/storage/sqlite-schema.js +0 -1
- package/dist/core/storage/sqlite-storage.d.ts +0 -1
- package/dist/core/storage/sqlite-storage.js +0 -1
- package/dist/core/storage/storage-factory.d.ts +0 -1
- package/dist/core/storage/storage-factory.js +0 -1
- package/dist/core/storage/validation.d.ts +0 -1
- package/dist/core/storage/validation.js +0 -1
- package/dist/core/storage/world-storage.d.ts +0 -1
- package/dist/core/storage/world-storage.js +0 -1
- package/dist/core/subscription.d.ts +0 -1
- package/dist/core/subscription.js +0 -1
- package/dist/core/tool-utils.d.ts +0 -1
- package/dist/core/tool-utils.js +0 -1
- package/dist/core/types.d.ts +0 -1
- package/dist/core/types.js +0 -1
- package/dist/core/utils.d.ts +0 -1
- package/dist/core/utils.js +0 -1
- package/dist/public/assets/index-BO20H4xt.js +96 -0
- package/dist/public/assets/{index-C9kPXL6G.css → index-ETY7W5_S.css} +1 -1
- package/dist/public/index.html +2 -2
- package/dist/server/api.js +29 -1
- package/dist/server/index.js +4 -4
- package/dist/server/sse-handler.d.ts +2 -1
- package/dist/server/sse-handler.js +10 -1
- package/migrations/0000_init_base_schema.sql +129 -0
- package/migrations/0001_add_chat_id.sql +12 -0
- package/migrations/0002_add_llm_config.sql +9 -0
- package/migrations/0003_add_current_chat_id.sql +8 -0
- package/migrations/0004_add_mcp_config.sql +8 -0
- package/migrations/0005_add_message_id.sql +12 -0
- package/migrations/0006_add_reply_to_message_id.sql +12 -0
- package/migrations/0007_create_world_chats.sql +35 -0
- package/migrations/0008_create_events_table.sql +78 -0
- package/migrations/0009_add_event_sequences.sql +40 -0
- package/migrations/0010_add_tool_call_fields.sql +27 -0
- package/migrations/0011_add_event_metadata_indexes.sql +79 -0
- package/migrations/0012_add_tool_role.sql +78 -0
- package/migrations/0013_add_world_variables.sql +7 -0
- package/migrations/0014_add_main_agent_and_auto_reply.sql +10 -0
- package/package.json +5 -5
- package/dist/public/assets/index-DOQEHGWt.js +0 -96
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Features:
|
|
7
7
|
* - Sets up SSE response headers and connection
|
|
8
|
-
* - Wires world event listeners (MESSAGE, SSE, SYSTEM, WORLD)
|
|
8
|
+
* - Wires world event listeners (MESSAGE, SSE, SYSTEM, WORLD, CRUD)
|
|
9
9
|
* - Handles world activity state tracking (response-start, idle)
|
|
10
10
|
* - Forwards tool events (tool-start, tool-result, tool-error, tool-progress) as SSE events
|
|
11
|
+
* - Forwards CRUD events so frontends can refresh world/agent state in real time
|
|
11
12
|
* - Automatic stream completion when world becomes idle
|
|
12
13
|
* - Timeout fallback (60s) if world never becomes idle
|
|
13
14
|
* - Proper cleanup on client disconnect or stream end
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Features:
|
|
7
7
|
* - Sets up SSE response headers and connection
|
|
8
|
-
* - Wires world event listeners (MESSAGE, SSE, SYSTEM, WORLD)
|
|
8
|
+
* - Wires world event listeners (MESSAGE, SSE, SYSTEM, WORLD, CRUD)
|
|
9
9
|
* - Handles world activity state tracking (response-start, idle)
|
|
10
10
|
* - Forwards tool events (tool-start, tool-result, tool-error, tool-progress) as SSE events
|
|
11
|
+
* - Forwards CRUD events so frontends can refresh world/agent state in real time
|
|
11
12
|
* - Automatic stream completion when world becomes idle
|
|
12
13
|
* - Timeout fallback (60s) if world never becomes idle
|
|
13
14
|
* - Proper cleanup on client disconnect or stream end
|
|
@@ -211,6 +212,14 @@ export function createSSEHandler(req, res, world, context = 'sse', scopedChatId)
|
|
|
211
212
|
};
|
|
212
213
|
world.eventEmitter.on(EventType.SYSTEM, systemListener);
|
|
213
214
|
listeners.set(EventType.SYSTEM, systemListener);
|
|
215
|
+
const crudListener = (eventData) => {
|
|
216
|
+
if (!isChatEventInScope(eventData?.chatId, true)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
sendSSE({ type: EventType.CRUD, data: eventData });
|
|
220
|
+
};
|
|
221
|
+
world.eventEmitter.on(EventType.CRUD, crudListener);
|
|
222
|
+
listeners.set(EventType.CRUD, crudListener);
|
|
214
223
|
// Cleanup function to remove all listeners
|
|
215
224
|
const cleanupListeners = () => {
|
|
216
225
|
for (const [eventType, listener] of listeners.entries()) {
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
-- Migration: Initial base schema
|
|
2
|
+
-- Version: 0
|
|
3
|
+
-- Date: 2025-11-02
|
|
4
|
+
--
|
|
5
|
+
-- This is the base schema that creates the initial database structure.
|
|
6
|
+
-- All subsequent migrations (0001-0009) build upon this foundation.
|
|
7
|
+
--
|
|
8
|
+
-- Base Tables:
|
|
9
|
+
-- - worlds: Core world configuration (no LLM/chat columns yet)
|
|
10
|
+
-- - agents: Agent configuration with LLM settings
|
|
11
|
+
-- - agent_memory: Active conversation memory (no chat_id, message_id, reply_to_message_id yet)
|
|
12
|
+
-- - memory_archives: Archive session metadata
|
|
13
|
+
-- - archived_messages: Historical conversation content
|
|
14
|
+
-- - archive_statistics: Usage analytics
|
|
15
|
+
--
|
|
16
|
+
-- Note: This is the PRE-MIGRATION state. Tables like world_chats, events, event_sequences
|
|
17
|
+
-- and columns like chat_id, mcp_config, etc. are added by subsequent migrations.
|
|
18
|
+
|
|
19
|
+
-- Create worlds table (base version without migration columns)
|
|
20
|
+
CREATE TABLE IF NOT EXISTS worlds (
|
|
21
|
+
id TEXT PRIMARY KEY,
|
|
22
|
+
name TEXT NOT NULL,
|
|
23
|
+
description TEXT,
|
|
24
|
+
turn_limit INTEGER NOT NULL DEFAULT 5,
|
|
25
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
26
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
-- Create agents table (complete from start)
|
|
30
|
+
CREATE TABLE IF NOT EXISTS agents (
|
|
31
|
+
id TEXT NOT NULL,
|
|
32
|
+
world_id TEXT NOT NULL,
|
|
33
|
+
name TEXT NOT NULL,
|
|
34
|
+
type TEXT NOT NULL,
|
|
35
|
+
status TEXT DEFAULT 'inactive',
|
|
36
|
+
provider TEXT NOT NULL,
|
|
37
|
+
model TEXT NOT NULL,
|
|
38
|
+
system_prompt TEXT,
|
|
39
|
+
temperature REAL,
|
|
40
|
+
max_tokens INTEGER,
|
|
41
|
+
llm_call_count INTEGER DEFAULT 0,
|
|
42
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
43
|
+
last_active TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
44
|
+
last_llm_call TIMESTAMP,
|
|
45
|
+
PRIMARY KEY (id, world_id),
|
|
46
|
+
FOREIGN KEY (world_id) REFERENCES worlds(id) ON DELETE CASCADE
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
-- Create agent_memory table (base version without chat columns)
|
|
50
|
+
CREATE TABLE IF NOT EXISTS agent_memory (
|
|
51
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
52
|
+
agent_id TEXT NOT NULL,
|
|
53
|
+
world_id TEXT NOT NULL,
|
|
54
|
+
role TEXT NOT NULL CHECK (role IN ('system', 'user', 'assistant')),
|
|
55
|
+
content TEXT NOT NULL,
|
|
56
|
+
sender TEXT,
|
|
57
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
58
|
+
FOREIGN KEY (agent_id, world_id) REFERENCES agents(id, world_id) ON DELETE CASCADE
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
-- Create memory archives system
|
|
62
|
+
CREATE TABLE IF NOT EXISTS memory_archives (
|
|
63
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
64
|
+
agent_id TEXT NOT NULL,
|
|
65
|
+
world_id TEXT NOT NULL,
|
|
66
|
+
session_name TEXT,
|
|
67
|
+
archive_reason TEXT,
|
|
68
|
+
message_count INTEGER NOT NULL DEFAULT 0,
|
|
69
|
+
start_time TIMESTAMP,
|
|
70
|
+
end_time TIMESTAMP,
|
|
71
|
+
participants TEXT,
|
|
72
|
+
tags TEXT,
|
|
73
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
74
|
+
FOREIGN KEY (agent_id, world_id) REFERENCES agents(id, world_id) ON DELETE CASCADE
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
CREATE TABLE IF NOT EXISTS archived_messages (
|
|
78
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
79
|
+
archive_id INTEGER NOT NULL,
|
|
80
|
+
agent_id TEXT NOT NULL,
|
|
81
|
+
world_id TEXT NOT NULL,
|
|
82
|
+
role TEXT NOT NULL CHECK (role IN ('system', 'user', 'assistant')),
|
|
83
|
+
content TEXT NOT NULL,
|
|
84
|
+
sender TEXT,
|
|
85
|
+
original_timestamp TIMESTAMP,
|
|
86
|
+
FOREIGN KEY (archive_id) REFERENCES memory_archives(id) ON DELETE CASCADE,
|
|
87
|
+
FOREIGN KEY (agent_id, world_id) REFERENCES agents(id, world_id) ON DELETE CASCADE
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
CREATE TABLE IF NOT EXISTS archive_statistics (
|
|
91
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
92
|
+
agent_id TEXT NOT NULL,
|
|
93
|
+
world_id TEXT NOT NULL,
|
|
94
|
+
total_archives INTEGER DEFAULT 0,
|
|
95
|
+
total_messages INTEGER DEFAULT 0,
|
|
96
|
+
average_session_length REAL DEFAULT 0,
|
|
97
|
+
most_active_agent TEXT,
|
|
98
|
+
archive_frequency TEXT,
|
|
99
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
100
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
101
|
+
FOREIGN KEY (agent_id, world_id) REFERENCES agents(id, world_id) ON DELETE CASCADE
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
-- Create base indexes
|
|
105
|
+
CREATE INDEX IF NOT EXISTS idx_agents_world_id ON agents(world_id);
|
|
106
|
+
CREATE INDEX IF NOT EXISTS idx_agents_status ON agents(status);
|
|
107
|
+
CREATE INDEX IF NOT EXISTS idx_agent_memory_agent_world ON agent_memory(agent_id, world_id);
|
|
108
|
+
CREATE INDEX IF NOT EXISTS idx_memory_archives_agent_world ON memory_archives(agent_id, world_id);
|
|
109
|
+
CREATE INDEX IF NOT EXISTS idx_archived_messages_archive_id ON archived_messages(archive_id);
|
|
110
|
+
CREATE INDEX IF NOT EXISTS idx_archive_statistics_agent_world ON archive_statistics(agent_id, world_id);
|
|
111
|
+
|
|
112
|
+
-- Create triggers for automatic timestamp updates
|
|
113
|
+
CREATE TRIGGER IF NOT EXISTS worlds_updated_at
|
|
114
|
+
AFTER UPDATE ON worlds
|
|
115
|
+
BEGIN
|
|
116
|
+
UPDATE worlds SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
|
|
117
|
+
END;
|
|
118
|
+
|
|
119
|
+
CREATE TRIGGER IF NOT EXISTS agents_last_active
|
|
120
|
+
AFTER UPDATE ON agents
|
|
121
|
+
BEGIN
|
|
122
|
+
UPDATE agents SET last_active = CURRENT_TIMESTAMP WHERE id = NEW.id AND world_id = NEW.world_id;
|
|
123
|
+
END;
|
|
124
|
+
|
|
125
|
+
CREATE TRIGGER IF NOT EXISTS archive_statistics_updated_at
|
|
126
|
+
AFTER UPDATE ON archive_statistics
|
|
127
|
+
BEGIN
|
|
128
|
+
UPDATE archive_statistics SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
|
|
129
|
+
END;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- Migration: Add chat_id to agent_memory for chat session tracking
|
|
2
|
+
-- Version: 1
|
|
3
|
+
-- Date: 2025-08-01
|
|
4
|
+
--
|
|
5
|
+
-- This migration adds the chat_id column to the agent_memory table to enable
|
|
6
|
+
-- chat session management and message grouping by conversation context.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE agent_memory ADD COLUMN chat_id TEXT;
|
|
9
|
+
|
|
10
|
+
CREATE INDEX
|
|
11
|
+
IF NOT EXISTS idx_agent_memory_chat_id ON agent_memory
|
|
12
|
+
(chat_id);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Migration: Add LLM provider and model configuration to worlds
|
|
2
|
+
-- Version: 2
|
|
3
|
+
-- Date: 2025-09-15
|
|
4
|
+
--
|
|
5
|
+
-- This migration adds chat_llm_provider and chat_llm_model columns to the worlds
|
|
6
|
+
-- table, enabling per-world LLM configuration for chat interactions.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE worlds ADD COLUMN chat_llm_provider TEXT;
|
|
9
|
+
ALTER TABLE worlds ADD COLUMN chat_llm_model TEXT;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Migration: Add current_chat_id to worlds for active chat tracking
|
|
2
|
+
-- Version: 3
|
|
3
|
+
-- Date: 2025-09-20
|
|
4
|
+
--
|
|
5
|
+
-- This migration adds the current_chat_id column to the worlds table to track
|
|
6
|
+
-- which chat session is currently active in each world.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE worlds ADD COLUMN current_chat_id TEXT;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
-- Migration: Add MCP (Model Context Protocol) configuration to worlds
|
|
2
|
+
-- Version: 4
|
|
3
|
+
-- Date: 2025-10-10
|
|
4
|
+
--
|
|
5
|
+
-- This migration adds the mcp_config column to the worlds table to store
|
|
6
|
+
-- Model Context Protocol server configurations as JSON.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE worlds ADD COLUMN mcp_config TEXT;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- Migration: Add message_id to agent_memory for message identification
|
|
2
|
+
-- Version: 5
|
|
3
|
+
-- Date: 2025-10-21
|
|
4
|
+
--
|
|
5
|
+
-- This migration adds the message_id column to the agent_memory table to enable
|
|
6
|
+
-- unique identification of messages for features like message editing and threading.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE agent_memory ADD COLUMN message_id TEXT;
|
|
9
|
+
|
|
10
|
+
CREATE INDEX
|
|
11
|
+
IF NOT EXISTS idx_agent_memory_message_id ON agent_memory
|
|
12
|
+
(message_id);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- Migration: Add reply_to_message_id for message threading support
|
|
2
|
+
-- Version: 6
|
|
3
|
+
-- Date: 2025-10-25
|
|
4
|
+
--
|
|
5
|
+
-- This migration adds the reply_to_message_id column to the agent_memory table
|
|
6
|
+
-- to enable message threading and conversation context tracking.
|
|
7
|
+
|
|
8
|
+
ALTER TABLE agent_memory ADD COLUMN reply_to_message_id TEXT;
|
|
9
|
+
|
|
10
|
+
CREATE INDEX
|
|
11
|
+
IF NOT EXISTS idx_agent_memory_reply_to_message_id ON agent_memory
|
|
12
|
+
(reply_to_message_id);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
-- Migration: Create world_chats table for chat session management
|
|
2
|
+
-- Version: 7
|
|
3
|
+
-- Date: 2025-10-28
|
|
4
|
+
--
|
|
5
|
+
-- This migration creates the world_chats table to manage chat sessions within worlds,
|
|
6
|
+
-- including metadata like name, description, message count, and tags.
|
|
7
|
+
|
|
8
|
+
CREATE TABLE
|
|
9
|
+
IF NOT EXISTS world_chats
|
|
10
|
+
(
|
|
11
|
+
id TEXT PRIMARY KEY,
|
|
12
|
+
world_id TEXT NOT NULL,
|
|
13
|
+
name TEXT NOT NULL,
|
|
14
|
+
description TEXT,
|
|
15
|
+
message_count INTEGER DEFAULT 0,
|
|
16
|
+
tags TEXT,
|
|
17
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
18
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
19
|
+
FOREIGN KEY
|
|
20
|
+
(world_id) REFERENCES worlds
|
|
21
|
+
(id) ON
|
|
22
|
+
DELETE CASCADE
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
CREATE INDEX
|
|
26
|
+
IF NOT EXISTS idx_world_chats_world_id ON world_chats
|
|
27
|
+
(world_id);
|
|
28
|
+
|
|
29
|
+
CREATE TRIGGER
|
|
30
|
+
IF NOT EXISTS world_chats_updated_at
|
|
31
|
+
AFTER
|
|
32
|
+
UPDATE ON world_chats
|
|
33
|
+
BEGIN
|
|
34
|
+
UPDATE world_chats SET updated_at = CURRENT_TIMESTAMP WHERE id = NEW.id;
|
|
35
|
+
END;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
-- Migration: Create events table for persistent event storage
|
|
2
|
+
-- Version: 8
|
|
3
|
+
-- Date: 2025-10-30
|
|
4
|
+
--
|
|
5
|
+
-- This migration creates the events table to store world emitter events with proper
|
|
6
|
+
-- foreign key relationships and cascade delete behavior.
|
|
7
|
+
--
|
|
8
|
+
-- Table Design:
|
|
9
|
+
-- - id: Text primary key (UUID format)
|
|
10
|
+
-- - world_id: Foreign key to worlds table with CASCADE delete
|
|
11
|
+
-- - chat_id: Foreign key to world_chats table with CASCADE delete (nullable)
|
|
12
|
+
-- - seq: Sequence number for ordering within a world/chat (nullable, auto-incremented per world/chat)
|
|
13
|
+
-- - type: Event type (message, sse, tool, system, etc.)
|
|
14
|
+
-- - payload: JSON column for event data (uses JSON1 extension)
|
|
15
|
+
-- - meta: JSON column for metadata like timestamp, sender, etc.
|
|
16
|
+
-- - created_at: Timestamp of event creation
|
|
17
|
+
--
|
|
18
|
+
-- Indexes:
|
|
19
|
+
-- - Composite index on (world_id, chat_id, created_at) for efficient time-based queries
|
|
20
|
+
-- - Composite index on (world_id, chat_id, seq) for efficient sequence-based queries
|
|
21
|
+
--
|
|
22
|
+
-- Cascade Delete Behavior:
|
|
23
|
+
-- - When a world is deleted, all events for that world are automatically deleted
|
|
24
|
+
-- - When a chat is deleted, all events for that chat are automatically deleted
|
|
25
|
+
-- - Foreign keys enforce referential integrity
|
|
26
|
+
|
|
27
|
+
-- Create events table
|
|
28
|
+
CREATE TABLE
|
|
29
|
+
IF NOT EXISTS events
|
|
30
|
+
(
|
|
31
|
+
id TEXT PRIMARY KEY,
|
|
32
|
+
world_id TEXT NOT NULL,
|
|
33
|
+
chat_id TEXT,
|
|
34
|
+
seq INTEGER,
|
|
35
|
+
type TEXT NOT NULL,
|
|
36
|
+
payload TEXT NOT NULL, -- JSON data stored as text (JSON1 extension)
|
|
37
|
+
meta TEXT, -- JSON metadata stored as text
|
|
38
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
39
|
+
|
|
40
|
+
-- Foreign key constraints with CASCADE delete
|
|
41
|
+
-- When a world is deleted, all its events are deleted
|
|
42
|
+
FOREIGN KEY
|
|
43
|
+
(world_id) REFERENCES worlds
|
|
44
|
+
(id) ON
|
|
45
|
+
DELETE CASCADE,
|
|
46
|
+
|
|
47
|
+
-- When a chat is deleted, all its events are deleted
|
|
48
|
+
-- Note: This uses a conditional foreign key - events with NULL chat_id won't be constrained
|
|
49
|
+
FOREIGN KEY (chat_id)
|
|
50
|
+
REFERENCES world_chats
|
|
51
|
+
(id) ON
|
|
52
|
+
DELETE CASCADE
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
-- Create indexes for efficient queries
|
|
56
|
+
-- Index for time-based queries within a world/chat context
|
|
57
|
+
CREATE INDEX
|
|
58
|
+
IF NOT EXISTS idx_events_world_chat_time
|
|
59
|
+
ON events
|
|
60
|
+
(world_id, chat_id, created_at);
|
|
61
|
+
|
|
62
|
+
-- Index for sequence-based queries within a world/chat context
|
|
63
|
+
CREATE INDEX
|
|
64
|
+
IF NOT EXISTS idx_events_world_chat_seq
|
|
65
|
+
ON events
|
|
66
|
+
(world_id, chat_id, seq);
|
|
67
|
+
|
|
68
|
+
-- Index for event type queries
|
|
69
|
+
CREATE INDEX
|
|
70
|
+
IF NOT EXISTS idx_events_type
|
|
71
|
+
ON events
|
|
72
|
+
(type);
|
|
73
|
+
|
|
74
|
+
-- Index for world_id alone for efficient world-level queries
|
|
75
|
+
CREATE INDEX
|
|
76
|
+
IF NOT EXISTS idx_events_world_id
|
|
77
|
+
ON events
|
|
78
|
+
(world_id);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
-- Migration: Add auto-incrementing sequence numbers to events
|
|
2
|
+
-- Version: 9
|
|
3
|
+
-- Date: 2025-11-06 (Updated)
|
|
4
|
+
--
|
|
5
|
+
-- This migration ensures that the seq column in events table auto-increments
|
|
6
|
+
-- within each world_id/chat_id context using MAX(seq) + 1 approach.
|
|
7
|
+
--
|
|
8
|
+
-- Approach:
|
|
9
|
+
-- - The seq column already exists in the events table (created in 0008)
|
|
10
|
+
-- - No separate sequence tracking table is needed
|
|
11
|
+
-- - Applications will use: COALESCE((SELECT MAX(seq) FROM events WHERE ...), 0) + 1
|
|
12
|
+
-- - Transaction isolation ensures no race conditions
|
|
13
|
+
--
|
|
14
|
+
-- Backfill Strategy:
|
|
15
|
+
-- - Assign sequence numbers to existing events based on creation time
|
|
16
|
+
-- - Uses ROW_NUMBER() partitioned by world_id and chat_id
|
|
17
|
+
-- - Orders by created_at to maintain chronological sequence
|
|
18
|
+
|
|
19
|
+
-- Backfill existing events with sequence numbers if they have NULL seq
|
|
20
|
+
-- This handles migration of existing data
|
|
21
|
+
-- Note: SQLite requires a CTE for window functions in UPDATE
|
|
22
|
+
WITH
|
|
23
|
+
numbered_events
|
|
24
|
+
AS
|
|
25
|
+
(
|
|
26
|
+
SELECT
|
|
27
|
+
rowid,
|
|
28
|
+
ROW_NUMBER() OVER (
|
|
29
|
+
PARTITION BY world_id,
|
|
30
|
+
CASE WHEN chat_id IS NULL THEN '' ELSE chat_id END
|
|
31
|
+
ORDER BY created_at ASC
|
|
32
|
+
) as new_seq
|
|
33
|
+
FROM events
|
|
34
|
+
WHERE seq IS NULL
|
|
35
|
+
)
|
|
36
|
+
UPDATE events
|
|
37
|
+
SET seq = (SELECT new_seq
|
|
38
|
+
FROM numbered_events
|
|
39
|
+
WHERE numbered_events.rowid = events.rowid)
|
|
40
|
+
WHERE seq IS NULL;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- Migration: Add tool call fields for approval message persistence
|
|
2
|
+
-- Version: 10
|
|
3
|
+
-- Date: 2025-11-05
|
|
4
|
+
--
|
|
5
|
+
-- This migration adds support for storing tool call information in agent memory,
|
|
6
|
+
-- which is essential for persisting approval request/response messages.
|
|
7
|
+
--
|
|
8
|
+
-- Changes:
|
|
9
|
+
-- - Add tool_calls column (TEXT) to store JSON array of tool call objects
|
|
10
|
+
-- - Add tool_call_id column (TEXT) to store tool call identifier for tool responses
|
|
11
|
+
--
|
|
12
|
+
-- Usage:
|
|
13
|
+
-- - tool_calls: JSON serialized array for assistant messages with function calls
|
|
14
|
+
-- Example: [{"id":"call_123","type":"function","function":{"name":"approve","arguments":"{}"}}]
|
|
15
|
+
-- - tool_call_id: String identifier for tool role messages responding to a tool call
|
|
16
|
+
-- Example: "approval_abc123"
|
|
17
|
+
--
|
|
18
|
+
-- These fields enable:
|
|
19
|
+
-- - Persistence of approval request messages (role='assistant' with tool_calls)
|
|
20
|
+
-- - Persistence of approval response messages (role='tool' with tool_call_id)
|
|
21
|
+
-- - Full reconstruction of approval conversation flows after page refresh
|
|
22
|
+
|
|
23
|
+
-- Add tool_calls column for storing JSON array of tool call objects
|
|
24
|
+
ALTER TABLE agent_memory ADD COLUMN tool_calls TEXT;
|
|
25
|
+
|
|
26
|
+
-- Add tool_call_id column for tool response messages
|
|
27
|
+
ALTER TABLE agent_memory ADD COLUMN tool_call_id TEXT;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
-- Migration: Add indexes on JSON metadata fields for fast filtering
|
|
2
|
+
-- Version: 11
|
|
3
|
+
-- Date: 2025-11-07
|
|
4
|
+
--
|
|
5
|
+
-- This migration adds indexes on commonly queried JSON metadata fields to improve
|
|
6
|
+
-- performance of event filtering operations. SQLite's JSON1 extension allows indexing
|
|
7
|
+
-- on json_extract() expressions.
|
|
8
|
+
--
|
|
9
|
+
-- Indexed Fields:
|
|
10
|
+
-- - ownerAgentIds: Array of agent IDs that have this event in memory
|
|
11
|
+
-- - recipientAgentId: Intended recipient agent ID
|
|
12
|
+
-- - messageDirection: Message flow direction (outgoing/incoming/broadcast)
|
|
13
|
+
-- - isMemoryOnly: Flag for messages saved but not triggering response
|
|
14
|
+
-- - isCrossAgentMessage: Flag for agent-to-agent communication
|
|
15
|
+
-- - threadRootId: Root message ID for threading queries
|
|
16
|
+
-- - hasToolCalls: Flag for messages containing tool calls
|
|
17
|
+
--
|
|
18
|
+
-- Performance Impact:
|
|
19
|
+
-- - Significantly improves filtering queries on metadata fields
|
|
20
|
+
-- - Composite index optimizes common query patterns (world + chat + owner)
|
|
21
|
+
-- - Uses SQLite JSON1 extension (built-in since SQLite 3.38.0)
|
|
22
|
+
|
|
23
|
+
-- Index on ownerAgentIds array (for agent filtering)
|
|
24
|
+
-- Note: Array search requires LIKE operator with pattern %"agentId"%
|
|
25
|
+
CREATE INDEX
|
|
26
|
+
IF NOT EXISTS idx_events_owner_agents
|
|
27
|
+
ON events
|
|
28
|
+
(json_extract
|
|
29
|
+
(meta, '$.ownerAgentIds'));
|
|
30
|
+
|
|
31
|
+
-- Index on recipientAgentId (for recipient filtering)
|
|
32
|
+
CREATE INDEX
|
|
33
|
+
IF NOT EXISTS idx_events_recipient_agent
|
|
34
|
+
ON events
|
|
35
|
+
(json_extract
|
|
36
|
+
(meta, '$.recipientAgentId'));
|
|
37
|
+
|
|
38
|
+
-- Index on messageDirection (for direction filtering)
|
|
39
|
+
CREATE INDEX
|
|
40
|
+
IF NOT EXISTS idx_events_message_direction
|
|
41
|
+
ON events
|
|
42
|
+
(json_extract
|
|
43
|
+
(meta, '$.messageDirection'));
|
|
44
|
+
|
|
45
|
+
-- Index on isMemoryOnly flag (for memory-only message filtering)
|
|
46
|
+
CREATE INDEX
|
|
47
|
+
IF NOT EXISTS idx_events_memory_only
|
|
48
|
+
ON events
|
|
49
|
+
(json_extract
|
|
50
|
+
(meta, '$.isMemoryOnly'));
|
|
51
|
+
|
|
52
|
+
-- Index on isCrossAgentMessage flag (for cross-agent message filtering)
|
|
53
|
+
CREATE INDEX
|
|
54
|
+
IF NOT EXISTS idx_events_cross_agent
|
|
55
|
+
ON events
|
|
56
|
+
(json_extract
|
|
57
|
+
(meta, '$.isCrossAgentMessage'));
|
|
58
|
+
|
|
59
|
+
-- Index on threadRootId (for thread queries)
|
|
60
|
+
CREATE INDEX
|
|
61
|
+
IF NOT EXISTS idx_events_thread_root
|
|
62
|
+
ON events
|
|
63
|
+
(json_extract
|
|
64
|
+
(meta, '$.threadRootId'));
|
|
65
|
+
|
|
66
|
+
-- Index on hasToolCalls flag (for tool call filtering)
|
|
67
|
+
CREATE INDEX
|
|
68
|
+
IF NOT EXISTS idx_events_has_tool_calls
|
|
69
|
+
ON events
|
|
70
|
+
(json_extract
|
|
71
|
+
(meta, '$.hasToolCalls'));
|
|
72
|
+
|
|
73
|
+
-- Composite index for common query pattern: filter by world, chat, and owner agent
|
|
74
|
+
-- This is the most common query pattern in the web UI (agent-specific message views)
|
|
75
|
+
CREATE INDEX
|
|
76
|
+
IF NOT EXISTS idx_events_world_chat_owner
|
|
77
|
+
ON events
|
|
78
|
+
(world_id, chat_id, json_extract
|
|
79
|
+
(meta, '$.ownerAgentIds'));
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
-- Migration: Add 'tool' role support to agent_memory and archived_messages
|
|
2
|
+
-- Version: 0012
|
|
3
|
+
-- Date: 2025-11-08
|
|
4
|
+
--
|
|
5
|
+
-- Purpose: Allow role='tool' for tool result messages in approval flow
|
|
6
|
+
-- This requires recreating tables since SQLite doesn't support modifying CHECK constraints
|
|
7
|
+
--
|
|
8
|
+
-- Note: Migration runner handles transactions automatically, so no explicit BEGIN/COMMIT needed
|
|
9
|
+
|
|
10
|
+
PRAGMA foreign_keys=OFF;
|
|
11
|
+
|
|
12
|
+
-- Clean up any existing backup tables from failed migration attempts
|
|
13
|
+
DROP TABLE IF EXISTS agent_memory_backup;
|
|
14
|
+
DROP TABLE IF EXISTS archived_messages_backup;
|
|
15
|
+
|
|
16
|
+
-- Backup agent_memory (copy ALL columns as-is)
|
|
17
|
+
CREATE TABLE agent_memory_backup AS SELECT * FROM agent_memory;
|
|
18
|
+
|
|
19
|
+
-- Drop and recreate agent_memory with updated constraint
|
|
20
|
+
DROP TABLE agent_memory;
|
|
21
|
+
|
|
22
|
+
CREATE TABLE agent_memory (
|
|
23
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
24
|
+
agent_id TEXT NOT NULL,
|
|
25
|
+
world_id TEXT NOT NULL,
|
|
26
|
+
role TEXT NOT NULL CHECK (role IN ('system', 'user', 'assistant', 'tool')),
|
|
27
|
+
content TEXT NOT NULL,
|
|
28
|
+
sender TEXT,
|
|
29
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
30
|
+
chat_id TEXT,
|
|
31
|
+
message_id TEXT,
|
|
32
|
+
reply_to_message_id TEXT,
|
|
33
|
+
tool_calls TEXT,
|
|
34
|
+
tool_call_id TEXT,
|
|
35
|
+
FOREIGN KEY (agent_id, world_id) REFERENCES agents(id, world_id) ON DELETE CASCADE
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
-- Restore data from backup (explicitly list columns to handle any schema differences)
|
|
39
|
+
INSERT INTO agent_memory (id, agent_id, world_id, role, content, sender, created_at, chat_id, message_id, reply_to_message_id, tool_calls, tool_call_id)
|
|
40
|
+
SELECT id, agent_id, world_id, role, content, sender, created_at, chat_id, message_id, reply_to_message_id, tool_calls, tool_call_id
|
|
41
|
+
FROM agent_memory_backup;
|
|
42
|
+
DROP TABLE agent_memory_backup;
|
|
43
|
+
|
|
44
|
+
-- Recreate indexes for agent_memory
|
|
45
|
+
CREATE INDEX IF NOT EXISTS idx_agent_memory_agent_world ON agent_memory(agent_id, world_id);
|
|
46
|
+
CREATE INDEX IF NOT EXISTS idx_agent_memory_chat_id ON agent_memory(chat_id);
|
|
47
|
+
CREATE INDEX IF NOT EXISTS idx_agent_memory_message_id ON agent_memory(message_id);
|
|
48
|
+
CREATE INDEX IF NOT EXISTS idx_agent_memory_reply_to ON agent_memory(reply_to_message_id);
|
|
49
|
+
|
|
50
|
+
-- Backup archived_messages (copy ALL columns as-is)
|
|
51
|
+
CREATE TABLE archived_messages_backup AS SELECT * FROM archived_messages;
|
|
52
|
+
|
|
53
|
+
-- Drop and recreate archived_messages with updated constraint
|
|
54
|
+
DROP TABLE archived_messages;
|
|
55
|
+
|
|
56
|
+
CREATE TABLE archived_messages (
|
|
57
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
58
|
+
archive_id INTEGER NOT NULL,
|
|
59
|
+
agent_id TEXT NOT NULL,
|
|
60
|
+
world_id TEXT NOT NULL,
|
|
61
|
+
role TEXT NOT NULL CHECK (role IN ('system', 'user', 'assistant', 'tool')),
|
|
62
|
+
content TEXT NOT NULL,
|
|
63
|
+
sender TEXT,
|
|
64
|
+
original_timestamp TIMESTAMP,
|
|
65
|
+
FOREIGN KEY (archive_id) REFERENCES memory_archives(id) ON DELETE CASCADE,
|
|
66
|
+
FOREIGN KEY (agent_id, world_id) REFERENCES agents(id, world_id) ON DELETE CASCADE
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
-- Restore data from backup (explicitly list columns for archived_messages)
|
|
70
|
+
INSERT INTO archived_messages (id, archive_id, agent_id, world_id, role, content, sender, original_timestamp)
|
|
71
|
+
SELECT id, archive_id, agent_id, world_id, role, content, sender, original_timestamp
|
|
72
|
+
FROM archived_messages_backup;
|
|
73
|
+
DROP TABLE archived_messages_backup;
|
|
74
|
+
|
|
75
|
+
-- Recreate index for archived_messages
|
|
76
|
+
CREATE INDEX IF NOT EXISTS idx_archived_messages_archive_id ON archived_messages(archive_id);
|
|
77
|
+
|
|
78
|
+
PRAGMA foreign_keys=ON;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
-- Migration: Add world main_agent and agent auto_reply fields
|
|
2
|
+
-- Version: 14
|
|
3
|
+
-- Date: 2026-02-13
|
|
4
|
+
--
|
|
5
|
+
-- Adds:
|
|
6
|
+
-- - worlds.main_agent (TEXT, nullable)
|
|
7
|
+
-- - agents.auto_reply (INTEGER, default 1)
|
|
8
|
+
|
|
9
|
+
ALTER TABLE worlds ADD COLUMN main_agent TEXT;
|
|
10
|
+
ALTER TABLE agents ADD COLUMN auto_reply INTEGER NOT NULL DEFAULT 1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agent-world",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"web"
|
|
21
21
|
],
|
|
22
22
|
"bin": {
|
|
23
|
-
"agent-world": "
|
|
24
|
-
"agent-world-cli": "
|
|
25
|
-
"agent-world-server": "
|
|
23
|
+
"agent-world": "bin/agent-world.js",
|
|
24
|
+
"agent-world-cli": "bin/agent-world-cli.js",
|
|
25
|
+
"agent-world-server": "bin/agent-world-server.js"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"dev": "npm run web:dev",
|
|
@@ -80,6 +80,7 @@
|
|
|
80
80
|
"nanoid": "^5.1.5",
|
|
81
81
|
"open": "^11.0.0",
|
|
82
82
|
"openai": "^6.15.0",
|
|
83
|
+
"commander": "^14.0.0",
|
|
83
84
|
"pino": "^10.0.0",
|
|
84
85
|
"pino-pretty": "^13.1.3",
|
|
85
86
|
"sqlite3": "^5.1.7",
|
|
@@ -97,7 +98,6 @@
|
|
|
97
98
|
"@vitest/ui": "^4.0.16",
|
|
98
99
|
"autoprefixer": "^10.4.23",
|
|
99
100
|
"chai": "^6.2.1",
|
|
100
|
-
"commander": "^14.0.0",
|
|
101
101
|
"npm-run-all": "^4.1.5",
|
|
102
102
|
"postcss": "^8.5.6",
|
|
103
103
|
"tailwindcss": "^4.1.18",
|