@relaycast/engine 12.2.1 → 12.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/actor/credential-tag.d.ts +14 -0
- package/dist/adapters/actor/credential-tag.d.ts.map +1 -0
- package/dist/adapters/actor/credential-tag.js +30 -0
- package/dist/adapters/actor/credential-tag.js.map +1 -0
- package/dist/adapters/actor/database.d.ts +50 -0
- package/dist/adapters/actor/database.d.ts.map +1 -0
- package/dist/adapters/actor/database.js +86 -0
- package/dist/adapters/actor/database.js.map +1 -0
- package/dist/adapters/actor/ephemeral-outbox.d.ts +16 -0
- package/dist/adapters/actor/ephemeral-outbox.d.ts.map +1 -0
- package/dist/adapters/actor/ephemeral-outbox.js +53 -0
- package/dist/adapters/actor/ephemeral-outbox.js.map +1 -0
- package/dist/adapters/actor/event-queue.d.ts +23 -0
- package/dist/adapters/actor/event-queue.d.ts.map +1 -0
- package/dist/adapters/actor/event-queue.js +31 -0
- package/dist/adapters/actor/event-queue.js.map +1 -0
- package/dist/adapters/actor/files.d.ts +66 -0
- package/dist/adapters/actor/files.d.ts.map +1 -0
- package/dist/adapters/actor/files.js +83 -0
- package/dist/adapters/actor/files.js.map +1 -0
- package/dist/adapters/actor/http.d.ts +19 -0
- package/dist/adapters/actor/http.d.ts.map +1 -0
- package/dist/adapters/actor/http.js +2 -0
- package/dist/adapters/actor/http.js.map +1 -0
- package/dist/adapters/actor/index.d.ts +90 -0
- package/dist/adapters/actor/index.d.ts.map +1 -0
- package/dist/adapters/actor/index.js +299 -0
- package/dist/adapters/actor/index.js.map +1 -0
- package/dist/adapters/actor/kv.d.ts +21 -0
- package/dist/adapters/actor/kv.d.ts.map +1 -0
- package/dist/adapters/actor/kv.js +33 -0
- package/dist/adapters/actor/kv.js.map +1 -0
- package/dist/adapters/actor/migrations.d.ts +15 -0
- package/dist/adapters/actor/migrations.d.ts.map +1 -0
- package/dist/adapters/actor/migrations.generated.d.ts +5 -0
- package/dist/adapters/actor/migrations.generated.d.ts.map +1 -0
- package/dist/adapters/actor/migrations.generated.js +842 -0
- package/dist/adapters/actor/migrations.generated.js.map +1 -0
- package/dist/adapters/actor/migrations.js +32 -0
- package/dist/adapters/actor/migrations.js.map +1 -0
- package/dist/adapters/node/files.d.ts +2 -0
- package/dist/adapters/node/files.d.ts.map +1 -1
- package/dist/adapters/node/files.js +31 -3
- package/dist/adapters/node/files.js.map +1 -1
- package/dist/adapters/node/index.js +1 -1
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/auth/credentialTags.d.ts +43 -0
- package/dist/auth/credentialTags.d.ts.map +1 -0
- package/dist/auth/credentialTags.js +106 -0
- package/dist/auth/credentialTags.js.map +1 -0
- package/dist/auth/credentials.d.ts +103 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +147 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/auth/index.d.ts +7 -4
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +115 -61
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/tokenKind.d.ts +17 -26
- package/dist/auth/tokenKind.d.ts.map +1 -1
- package/dist/auth/tokenKind.js +17 -46
- package/dist/auth/tokenKind.js.map +1 -1
- package/dist/auth/workspaceExpiry.d.ts +2 -0
- package/dist/auth/workspaceExpiry.d.ts.map +1 -1
- package/dist/auth/workspaceExpiry.js +7 -0
- package/dist/auth/workspaceExpiry.js.map +1 -1
- package/dist/bin/secretEnv.d.ts +17 -0
- package/dist/bin/secretEnv.d.ts.map +1 -0
- package/dist/bin/secretEnv.js +33 -0
- package/dist/bin/secretEnv.js.map +1 -0
- package/dist/bin/serve.js +42 -4
- package/dist/bin/serve.js.map +1 -1
- package/dist/config/credentialEnv.d.ts +19 -0
- package/dist/config/credentialEnv.d.ts.map +1 -0
- package/dist/config/credentialEnv.js +53 -0
- package/dist/config/credentialEnv.js.map +1 -0
- package/dist/db/migrations/0079_credential_upgrades.sql +17 -0
- package/dist/db/schema.d.ts +164 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +20 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/engine/a2a.d.ts +1 -1
- package/dist/engine/a2a.d.ts.map +1 -1
- package/dist/engine/a2a.js +2 -2
- package/dist/engine/a2a.js.map +1 -1
- package/dist/engine/a2aEgress.d.ts +3 -2
- package/dist/engine/a2aEgress.d.ts.map +1 -1
- package/dist/engine/a2aEgress.js +5 -4
- package/dist/engine/a2aEgress.js.map +1 -1
- package/dist/engine/action.d.ts +12 -0
- package/dist/engine/action.d.ts.map +1 -1
- package/dist/engine/action.js +45 -1
- package/dist/engine/action.js.map +1 -1
- package/dist/engine/agent.d.ts +1 -0
- package/dist/engine/agent.d.ts.map +1 -1
- package/dist/engine/agent.js +51 -11
- package/dist/engine/agent.js.map +1 -1
- package/dist/engine/agentIdentity.d.ts.map +1 -1
- package/dist/engine/agentIdentity.js +2 -1
- package/dist/engine/agentIdentity.js.map +1 -1
- package/dist/engine/credentialUpgrade.d.ts +48 -0
- package/dist/engine/credentialUpgrade.d.ts.map +1 -0
- package/dist/engine/credentialUpgrade.js +176 -0
- package/dist/engine/credentialUpgrade.js.map +1 -0
- package/dist/engine/eventDispatch.d.ts.map +1 -1
- package/dist/engine/eventDispatch.js +3 -2
- package/dist/engine/eventDispatch.js.map +1 -1
- package/dist/engine/eventSubscription.d.ts +4 -4
- package/dist/engine/file.d.ts +8 -0
- package/dist/engine/file.d.ts.map +1 -1
- package/dist/engine/file.js +18 -5
- package/dist/engine/file.js.map +1 -1
- package/dist/engine/inboundWebhook.d.ts +2 -0
- package/dist/engine/inboundWebhook.d.ts.map +1 -1
- package/dist/engine/inboundWebhook.js +10 -4
- package/dist/engine/inboundWebhook.js.map +1 -1
- package/dist/engine/internalAdmin.d.ts +80 -0
- package/dist/engine/internalAdmin.d.ts.map +1 -0
- package/dist/engine/internalAdmin.js +329 -0
- package/dist/engine/internalAdmin.js.map +1 -0
- package/dist/engine/invocationCompletion.d.ts.map +1 -1
- package/dist/engine/invocationCompletion.js +23 -5
- package/dist/engine/invocationCompletion.js.map +1 -1
- package/dist/engine/node.d.ts +38 -1
- package/dist/engine/node.d.ts.map +1 -1
- package/dist/engine/node.js +166 -11
- package/dist/engine/node.js.map +1 -1
- package/dist/engine/nodeContext.d.ts +2 -1
- package/dist/engine/nodeContext.d.ts.map +1 -1
- package/dist/engine/nodeContext.js +1 -1
- package/dist/engine/nodeContext.js.map +1 -1
- package/dist/engine/nodeDeliver.d.ts +2 -1
- package/dist/engine/nodeDeliver.d.ts.map +1 -1
- package/dist/engine/nodeDeliver.js +1 -1
- package/dist/engine/nodeDeliver.js.map +1 -1
- package/dist/engine/nodeLiveness.d.ts +7 -0
- package/dist/engine/nodeLiveness.d.ts.map +1 -1
- package/dist/engine/nodeLiveness.js +21 -0
- package/dist/engine/nodeLiveness.js.map +1 -1
- package/dist/engine/observerToken.d.ts +4 -0
- package/dist/engine/observerToken.d.ts.map +1 -1
- package/dist/engine/observerToken.js +14 -5
- package/dist/engine/observerToken.js.map +1 -1
- package/dist/engine/taskInvocation.d.ts +1 -1
- package/dist/engine/tokenRotate.d.ts.map +1 -1
- package/dist/engine/tokenRotate.js +4 -3
- package/dist/engine/tokenRotate.js.map +1 -1
- package/dist/engine/workspace.d.ts +8 -2
- package/dist/engine/workspace.d.ts.map +1 -1
- package/dist/engine/workspace.js +70 -21
- package/dist/engine/workspace.js.map +1 -1
- package/dist/engine/wsAuth.d.ts.map +1 -1
- package/dist/engine/wsAuth.js +14 -3
- package/dist/engine/wsAuth.js.map +1 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +31 -0
- package/dist/engine.js.map +1 -1
- package/dist/entrypoints/node.d.ts +3 -1
- package/dist/entrypoints/node.d.ts.map +1 -1
- package/dist/entrypoints/node.js +33 -1
- package/dist/entrypoints/node.js.map +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/gateway.d.ts +11 -0
- package/dist/gateway.d.ts.map +1 -0
- package/dist/gateway.js +16 -0
- package/dist/gateway.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/credentialNotice.d.ts +32 -0
- package/dist/lib/credentialNotice.d.ts.map +1 -0
- package/dist/lib/credentialNotice.js +76 -0
- package/dist/lib/credentialNotice.js.map +1 -0
- package/dist/lib/fileTokens.d.ts +30 -0
- package/dist/lib/fileTokens.d.ts.map +1 -0
- package/dist/lib/fileTokens.js +76 -0
- package/dist/lib/fileTokens.js.map +1 -0
- package/dist/lib/httpError.d.ts +1 -1
- package/dist/lib/httpResponse.d.ts +6 -6
- package/dist/middleware/admission.d.ts +1 -1
- package/dist/middleware/auth.d.ts.map +1 -1
- package/dist/middleware/auth.js +22 -31
- package/dist/middleware/auth.js.map +1 -1
- package/dist/middleware/idempotency.d.ts +1 -1
- package/dist/middleware/logger.d.ts.map +1 -1
- package/dist/middleware/logger.js +4 -1
- package/dist/middleware/logger.js.map +1 -1
- package/dist/ports/database.d.ts.map +1 -1
- package/dist/ports/database.js +8 -2
- package/dist/ports/database.js.map +1 -1
- package/dist/ports/files.d.ts +7 -1
- package/dist/ports/files.d.ts.map +1 -1
- package/dist/ports/index.d.ts +64 -1
- package/dist/ports/index.d.ts.map +1 -1
- package/dist/ports/index.js +4 -0
- package/dist/ports/index.js.map +1 -1
- package/dist/ports/telemetry.d.ts +1 -0
- package/dist/ports/telemetry.d.ts.map +1 -1
- package/dist/ports/telemetry.js +1 -0
- package/dist/ports/telemetry.js.map +1 -1
- package/dist/routes/action.d.ts.map +1 -1
- package/dist/routes/action.js +2 -1
- package/dist/routes/action.js.map +1 -1
- package/dist/routes/agent.d.ts.map +1 -1
- package/dist/routes/agent.js +33 -2
- package/dist/routes/agent.js.map +1 -1
- package/dist/routes/credential.d.ts +4 -0
- package/dist/routes/credential.d.ts.map +1 -0
- package/dist/routes/credential.js +97 -0
- package/dist/routes/credential.js.map +1 -0
- package/dist/routes/file.js +10 -4
- package/dist/routes/file.js.map +1 -1
- package/dist/routes/inboundWebhook.d.ts.map +1 -1
- package/dist/routes/inboundWebhook.js +11 -2
- package/dist/routes/inboundWebhook.js.map +1 -1
- package/dist/routes/internal.d.ts +14 -0
- package/dist/routes/internal.d.ts.map +1 -0
- package/dist/routes/internal.js +157 -0
- package/dist/routes/internal.js.map +1 -0
- package/dist/routes/node.d.ts.map +1 -1
- package/dist/routes/node.js +44 -2
- package/dist/routes/node.js.map +1 -1
- package/dist/routes/observerToken.js +1 -1
- package/dist/routes/observerToken.js.map +1 -1
- package/dist/routes/reaction.d.ts.map +1 -1
- package/dist/routes/reaction.js +3 -2
- package/dist/routes/reaction.js.map +1 -1
- package/dist/routes/receipt.d.ts.map +1 -1
- package/dist/routes/receipt.js +2 -1
- package/dist/routes/receipt.js.map +1 -1
- package/dist/routes/workspace.d.ts.map +1 -1
- package/dist/routes/workspace.js +12 -1
- package/dist/routes/workspace.js.map +1 -1
- package/package.json +12 -3
|
@@ -0,0 +1,842 @@
|
|
|
1
|
+
// Generated by scripts/generate-actor-migrations.mjs from src/db/migrations. Do not edit.
|
|
2
|
+
/** Each engine migration file, split into single statements. */
|
|
3
|
+
export const ACTOR_MIGRATIONS = [
|
|
4
|
+
[
|
|
5
|
+
"0000_broad_dagger.sql",
|
|
6
|
+
[
|
|
7
|
+
"CREATE TABLE `agents` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`name` text NOT NULL,\n\t`type` text DEFAULT 'agent' NOT NULL,\n\t`token_hash` text NOT NULL,\n\t`status` text DEFAULT 'online' NOT NULL,\n\t`persona` text,\n\t`metadata` text DEFAULT '{}',\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\t`last_seen` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
8
|
+
"CREATE UNIQUE INDEX `agents_token_hash_unique` ON `agents` (`token_hash`)",
|
|
9
|
+
"CREATE UNIQUE INDEX `agents_workspace_name_unique` ON `agents` (`workspace_id`,`name`)",
|
|
10
|
+
"CREATE INDEX `idx_agents_workspace` ON `agents` (`workspace_id`)",
|
|
11
|
+
"CREATE INDEX `idx_agents_token` ON `agents` (`token_hash`)",
|
|
12
|
+
"CREATE TABLE `channel_members` (\n\t`channel_id` text NOT NULL,\n\t`agent_id` text NOT NULL,\n\t`role` text DEFAULT 'member' NOT NULL,\n\t`joined_at` integer DEFAULT (unixepoch()) NOT NULL,\n\t`last_read_id` text,\n\tPRIMARY KEY(`channel_id`, `agent_id`),\n\tFOREIGN KEY (`channel_id`) REFERENCES `channels`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
13
|
+
"CREATE INDEX `idx_channel_members_agent` ON `channel_members` (`agent_id`)",
|
|
14
|
+
"CREATE TABLE `channels` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`name` text NOT NULL,\n\t`channel_type` integer DEFAULT 0 NOT NULL,\n\t`topic` text,\n\t`created_by` text,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\t`is_archived` integer DEFAULT false NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`created_by`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE no action\n)",
|
|
15
|
+
"CREATE UNIQUE INDEX `channels_workspace_name_unique` ON `channels` (`workspace_id`,`name`)",
|
|
16
|
+
"CREATE INDEX `idx_channels_workspace` ON `channels` (`workspace_id`)",
|
|
17
|
+
"CREATE TABLE `commands` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`command` text NOT NULL,\n\t`description` text NOT NULL,\n\t`handler_agent_id` text NOT NULL,\n\t`parameters` text DEFAULT '[]',\n\t`is_active` integer DEFAULT true NOT NULL,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`handler_agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
18
|
+
"CREATE UNIQUE INDEX `commands_workspace_command_unique` ON `commands` (`workspace_id`,`command`)",
|
|
19
|
+
"CREATE INDEX `idx_commands_workspace` ON `commands` (`workspace_id`)",
|
|
20
|
+
"CREATE INDEX `idx_commands_handler` ON `commands` (`handler_agent_id`)",
|
|
21
|
+
"CREATE TABLE `dm_conversations` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`channel_id` text NOT NULL,\n\t`dm_type` text DEFAULT '1:1' NOT NULL,\n\t`name` text,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`channel_id`) REFERENCES `channels`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
22
|
+
"CREATE INDEX `idx_dm_conversations_workspace` ON `dm_conversations` (`workspace_id`)",
|
|
23
|
+
"CREATE TABLE `dm_participants` (\n\t`conversation_id` text NOT NULL,\n\t`agent_id` text NOT NULL,\n\t`joined_at` integer DEFAULT (unixepoch()) NOT NULL,\n\t`left_at` integer,\n\tPRIMARY KEY(`conversation_id`, `agent_id`),\n\tFOREIGN KEY (`conversation_id`) REFERENCES `dm_conversations`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
24
|
+
"CREATE INDEX `idx_dm_participants_agent` ON `dm_participants` (`agent_id`)",
|
|
25
|
+
"CREATE TABLE `event_subscriptions` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`events` text NOT NULL,\n\t`filter` text,\n\t`url` text NOT NULL,\n\t`secret` text,\n\t`is_active` integer DEFAULT true NOT NULL,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
26
|
+
"CREATE INDEX `idx_event_subscriptions_workspace` ON `event_subscriptions` (`workspace_id`)",
|
|
27
|
+
"CREATE TABLE `files` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`uploaded_by` text NOT NULL,\n\t`filename` text NOT NULL,\n\t`content_type` text NOT NULL,\n\t`size_bytes` integer NOT NULL,\n\t`storage_key` text NOT NULL,\n\t`status` text DEFAULT 'pending' NOT NULL,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`uploaded_by`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE no action\n)",
|
|
28
|
+
"CREATE INDEX `idx_files_workspace` ON `files` (`workspace_id`,`created_at`)",
|
|
29
|
+
"CREATE INDEX `idx_files_uploader` ON `files` (`uploaded_by`)",
|
|
30
|
+
"CREATE TABLE `message_attachments` (\n\t`message_id` text NOT NULL,\n\t`file_id` text NOT NULL,\n\t`position` integer DEFAULT 0 NOT NULL,\n\tPRIMARY KEY(`message_id`, `file_id`),\n\tFOREIGN KEY (`message_id`) REFERENCES `messages`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`file_id`) REFERENCES `files`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
31
|
+
"CREATE INDEX `idx_message_attachments_file` ON `message_attachments` (`file_id`)",
|
|
32
|
+
"CREATE TABLE `messages` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`channel_id` text NOT NULL,\n\t`agent_id` text NOT NULL,\n\t`thread_id` text,\n\t`body` text NOT NULL,\n\t`blocks` text,\n\t`has_attachments` integer DEFAULT false NOT NULL,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\t`updated_at` integer,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`channel_id`) REFERENCES `channels`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE no action,\n\tFOREIGN KEY (`thread_id`) REFERENCES `messages`(`id`) ON UPDATE no action ON DELETE no action\n)",
|
|
33
|
+
"CREATE INDEX `idx_messages_channel_time` ON `messages` (`channel_id`,`id`)",
|
|
34
|
+
"CREATE INDEX `idx_messages_thread` ON `messages` (`thread_id`,`id`)",
|
|
35
|
+
"CREATE INDEX `idx_messages_workspace` ON `messages` (`workspace_id`,`id`)",
|
|
36
|
+
"CREATE TABLE `pending_events` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`event_type` text NOT NULL,\n\t`payload` text NOT NULL,\n\t`status` text DEFAULT 'pending' NOT NULL,\n\t`attempts` integer DEFAULT 0 NOT NULL,\n\t`max_attempts` integer DEFAULT 5 NOT NULL,\n\t`last_error` text,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\t`process_after` integer DEFAULT (unixepoch()) NOT NULL,\n\t`completed_at` integer,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
37
|
+
"CREATE INDEX `idx_pending_events_status` ON `pending_events` (`status`,`process_after`)",
|
|
38
|
+
"CREATE INDEX `idx_pending_events_workspace` ON `pending_events` (`workspace_id`)",
|
|
39
|
+
"CREATE TABLE `reactions` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`message_id` text NOT NULL,\n\t`agent_id` text NOT NULL,\n\t`emoji` text NOT NULL,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`message_id`) REFERENCES `messages`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
40
|
+
"CREATE UNIQUE INDEX `reactions_message_agent_emoji_unique` ON `reactions` (`message_id`,`agent_id`,`emoji`)",
|
|
41
|
+
"CREATE INDEX `idx_reactions_message` ON `reactions` (`message_id`)",
|
|
42
|
+
"CREATE TABLE `read_receipts` (\n\t`message_id` text NOT NULL,\n\t`agent_id` text NOT NULL,\n\t`read_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tPRIMARY KEY(`message_id`, `agent_id`),\n\tFOREIGN KEY (`message_id`) REFERENCES `messages`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
43
|
+
"CREATE INDEX `idx_read_receipts_message` ON `read_receipts` (`message_id`)",
|
|
44
|
+
"CREATE INDEX `idx_read_receipts_agent` ON `read_receipts` (`agent_id`,`read_at`)",
|
|
45
|
+
"CREATE TABLE `usage_records` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`period_start` integer NOT NULL,\n\t`period_end` integer NOT NULL,\n\t`messages_sent` integer DEFAULT 0 NOT NULL,\n\t`api_calls` integer DEFAULT 0 NOT NULL,\n\t`files_uploaded` integer DEFAULT 0 NOT NULL,\n\t`file_bytes` integer DEFAULT 0 NOT NULL,\n\t`ws_minutes` integer DEFAULT 0 NOT NULL,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
46
|
+
"CREATE INDEX `idx_usage_workspace_period` ON `usage_records` (`workspace_id`,`period_start`)",
|
|
47
|
+
"CREATE TABLE `webhooks` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`name` text NOT NULL,\n\t`channel_id` text NOT NULL,\n\t`created_by` text,\n\t`is_active` integer DEFAULT true NOT NULL,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`channel_id`) REFERENCES `channels`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`created_by`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE no action\n)",
|
|
48
|
+
"CREATE UNIQUE INDEX `webhooks_workspace_name_unique` ON `webhooks` (`workspace_id`,`name`)",
|
|
49
|
+
"CREATE INDEX `idx_webhooks_workspace` ON `webhooks` (`workspace_id`)",
|
|
50
|
+
"CREATE TABLE `workspaces` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`name` text NOT NULL,\n\t`api_key_hash` text NOT NULL,\n\t`system_prompt` text,\n\t`plan` text DEFAULT 'free' NOT NULL,\n\t`stripe_customer_id` text,\n\t`stripe_subscription_id` text,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\t`metadata` text DEFAULT '{}'\n)",
|
|
51
|
+
"CREATE UNIQUE INDEX `workspaces_name_unique` ON `workspaces` (`name`)",
|
|
52
|
+
"CREATE UNIQUE INDEX `workspaces_api_key_hash_unique` ON `workspaces` (`api_key_hash`)"
|
|
53
|
+
]
|
|
54
|
+
],
|
|
55
|
+
[
|
|
56
|
+
"0001_fts5_search.sql",
|
|
57
|
+
[
|
|
58
|
+
"CREATE VIRTUAL TABLE IF NOT EXISTS messages_fts USING fts5(\n id UNINDEXED,\n body,\n content=messages,\n content_rowid=rowid\n)",
|
|
59
|
+
"CREATE TRIGGER IF NOT EXISTS messages_fts_insert AFTER INSERT ON messages BEGIN\n INSERT INTO messages_fts(rowid, id, body) VALUES (NEW.rowid, NEW.id, NEW.body);\nEND",
|
|
60
|
+
"CREATE TRIGGER IF NOT EXISTS messages_fts_update AFTER UPDATE OF body ON messages BEGIN\n INSERT INTO messages_fts(messages_fts, rowid, id, body) VALUES('delete', OLD.rowid, OLD.id, OLD.body);\n INSERT INTO messages_fts(rowid, id, body) VALUES (NEW.rowid, NEW.id, NEW.body);\nEND",
|
|
61
|
+
"CREATE TRIGGER IF NOT EXISTS messages_fts_delete AFTER DELETE ON messages BEGIN\n INSERT INTO messages_fts(messages_fts, rowid, id, body) VALUES('delete', OLD.rowid, OLD.id, OLD.body);\nEND"
|
|
62
|
+
]
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"0002_add_metadata_columns.sql",
|
|
66
|
+
[
|
|
67
|
+
"ALTER TABLE channels ADD COLUMN metadata TEXT DEFAULT '{}'",
|
|
68
|
+
"ALTER TABLE messages ADD COLUMN metadata TEXT DEFAULT '{}'"
|
|
69
|
+
]
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
"0003_add_channel_mute.sql",
|
|
73
|
+
[
|
|
74
|
+
"ALTER TABLE channel_members ADD COLUMN is_muted INTEGER NOT NULL DEFAULT 0"
|
|
75
|
+
]
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
"0004_a2a_agents.sql",
|
|
79
|
+
[
|
|
80
|
+
"CREATE TABLE `a2a_agents` (\n\t`id` text PRIMARY KEY NOT NULL,\n\t`workspace_id` text NOT NULL,\n\t`relay_agent_id` text NOT NULL,\n\t`agent_card` text DEFAULT '{}' NOT NULL,\n\t`external_url` text NOT NULL,\n\t`auth_scheme` text,\n\t`auth_credential` text,\n\t`status` text DEFAULT 'active' NOT NULL,\n\t`messages_sent` integer DEFAULT 0 NOT NULL,\n\t`messages_recv` integer DEFAULT 0 NOT NULL,\n\t`last_health` integer,\n\t`health_failures` integer DEFAULT 0 NOT NULL,\n\t`created_at` integer DEFAULT (unixepoch()) NOT NULL,\n\t`updated_at` integer DEFAULT (unixepoch()) NOT NULL,\n\tFOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade,\n\tFOREIGN KEY (`relay_agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
81
|
+
"CREATE INDEX `idx_a2a_agents_workspace` ON `a2a_agents` (`workspace_id`)",
|
|
82
|
+
"CREATE UNIQUE INDEX `idx_a2a_agents_relay_agent` ON `a2a_agents` (`relay_agent_id`)"
|
|
83
|
+
]
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
"0005_certifications.sql",
|
|
87
|
+
[
|
|
88
|
+
"CREATE TABLE `certifications` (\n `id` text PRIMARY KEY NOT NULL,\n `workspace_id` text NOT NULL,\n `agent_url` text NOT NULL,\n `level` integer NOT NULL,\n `source` text NOT NULL DEFAULT 'manual',\n `status` text NOT NULL DEFAULT 'pending',\n `passed` integer NOT NULL DEFAULT false,\n `passed_tests` integer NOT NULL DEFAULT 0,\n `total_tests` integer NOT NULL DEFAULT 0,\n `monitor_enabled` integer NOT NULL DEFAULT false,\n `monitor_interval_minutes` integer NOT NULL DEFAULT 60,\n `last_run_at` integer,\n `results` text DEFAULT '[]',\n `created_at` integer NOT NULL DEFAULT (unixepoch()),\n `updated_at` integer NOT NULL DEFAULT (unixepoch()),\n FOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
89
|
+
"CREATE INDEX `idx_certifications_workspace` ON `certifications` (`workspace_id`,`created_at`)",
|
|
90
|
+
"CREATE INDEX `idx_certifications_agent_url` ON `certifications` (`agent_url`)",
|
|
91
|
+
"CREATE INDEX `idx_certifications_monitor_enabled` ON `certifications` (`monitor_enabled`,`updated_at`)"
|
|
92
|
+
]
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
"0006_message_logs.sql",
|
|
96
|
+
[
|
|
97
|
+
"CREATE TABLE `message_logs` (\n `id` text PRIMARY KEY NOT NULL,\n `workspace_id` text NOT NULL,\n `message_id` text NOT NULL,\n `channel_id` text NOT NULL,\n `agent_id` text NOT NULL,\n `conversation_id` text,\n `delivery_kind` text NOT NULL,\n `body` text NOT NULL,\n `content_type` text,\n `metadata` text DEFAULT '{}',\n `attachment_count` integer DEFAULT 0 NOT NULL,\n `mention_count` integer DEFAULT 0 NOT NULL,\n `latency_ms` integer DEFAULT 0 NOT NULL,\n `created_at` integer DEFAULT (unixepoch()) NOT NULL,\n FOREIGN KEY (`workspace_id`) REFERENCES `workspaces`(`id`) ON UPDATE no action ON DELETE cascade,\n FOREIGN KEY (`message_id`) REFERENCES `messages`(`id`) ON UPDATE no action ON DELETE cascade,\n FOREIGN KEY (`channel_id`) REFERENCES `channels`(`id`) ON UPDATE no action ON DELETE cascade,\n FOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE cascade\n)",
|
|
98
|
+
"CREATE UNIQUE INDEX `message_logs_message_unique` ON `message_logs` (`message_id`)",
|
|
99
|
+
"CREATE INDEX `idx_message_logs_workspace_time` ON `message_logs` (`workspace_id`, `id`)",
|
|
100
|
+
"CREATE INDEX `idx_message_logs_agent_time` ON `message_logs` (`agent_id`, `id`)",
|
|
101
|
+
"CREATE INDEX `idx_message_logs_channel_time` ON `message_logs` (`channel_id`, `id`)",
|
|
102
|
+
"CREATE INDEX `idx_message_logs_conversation_time` ON `message_logs` (`conversation_id`, `id`)"
|
|
103
|
+
]
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"0007_directory.sql",
|
|
107
|
+
[
|
|
108
|
+
"CREATE TABLE IF NOT EXISTS directory_agents (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n source_agent_id TEXT REFERENCES agents(id) ON DELETE SET NULL,\n slug TEXT NOT NULL,\n name TEXT NOT NULL,\n description TEXT,\n provider TEXT,\n endpoint_url TEXT,\n documentation_url TEXT,\n version TEXT,\n tags TEXT NOT NULL DEFAULT '[]',\n capabilities TEXT NOT NULL DEFAULT '{}',\n metadata TEXT NOT NULL DEFAULT '{}',\n status TEXT NOT NULL DEFAULT 'active',\n rating_sum INTEGER NOT NULL DEFAULT 0,\n rating_count INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n updated_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
109
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS directory_agents_workspace_slug_unique\n ON directory_agents(workspace_id, slug)",
|
|
110
|
+
"CREATE INDEX IF NOT EXISTS idx_directory_agents_workspace\n ON directory_agents(workspace_id, created_at)",
|
|
111
|
+
"CREATE INDEX IF NOT EXISTS idx_directory_agents_source_agent\n ON directory_agents(source_agent_id)",
|
|
112
|
+
"CREATE INDEX IF NOT EXISTS idx_directory_agents_status\n ON directory_agents(workspace_id, status)",
|
|
113
|
+
"CREATE TABLE IF NOT EXISTS directory_skills (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n directory_agent_id TEXT NOT NULL REFERENCES directory_agents(id) ON DELETE CASCADE,\n skill_id TEXT,\n name TEXT NOT NULL,\n description TEXT,\n tags TEXT NOT NULL DEFAULT '[]',\n metadata TEXT NOT NULL DEFAULT '{}',\n position INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
114
|
+
"CREATE INDEX IF NOT EXISTS idx_directory_skills_agent\n ON directory_skills(directory_agent_id, position)",
|
|
115
|
+
"CREATE INDEX IF NOT EXISTS idx_directory_skills_workspace\n ON directory_skills(workspace_id)",
|
|
116
|
+
"CREATE TABLE IF NOT EXISTS directory_ratings (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n directory_agent_id TEXT NOT NULL REFERENCES directory_agents(id) ON DELETE CASCADE,\n rater_agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,\n score INTEGER NOT NULL,\n review TEXT,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n updated_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
117
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS directory_ratings_agent_rater_unique\n ON directory_ratings(directory_agent_id, rater_agent_id)",
|
|
118
|
+
"CREATE INDEX IF NOT EXISTS idx_directory_ratings_workspace\n ON directory_ratings(workspace_id, created_at)",
|
|
119
|
+
"CREATE INDEX IF NOT EXISTS idx_directory_ratings_directory_agent\n ON directory_ratings(directory_agent_id, created_at)",
|
|
120
|
+
"CREATE VIRTUAL TABLE IF NOT EXISTS directory_agents_fts USING fts5(\n id UNINDEXED,\n name,\n description,\n provider,\n tags,\n content=directory_agents,\n content_rowid=rowid\n)",
|
|
121
|
+
"CREATE TRIGGER IF NOT EXISTS directory_agents_fts_insert\nAFTER INSERT ON directory_agents BEGIN\n INSERT INTO directory_agents_fts(rowid, id, name, description, provider, tags)\n VALUES (NEW.rowid, NEW.id, NEW.name, COALESCE(NEW.description, ''), COALESCE(NEW.provider, ''), COALESCE(NEW.tags, '[]'));\nEND",
|
|
122
|
+
"CREATE TRIGGER IF NOT EXISTS directory_agents_fts_update\nAFTER UPDATE OF name, description, provider, tags ON directory_agents BEGIN\n INSERT INTO directory_agents_fts(directory_agents_fts, rowid, id, name, description, provider, tags)\n VALUES ('delete', OLD.rowid, OLD.id, OLD.name, COALESCE(OLD.description, ''), COALESCE(OLD.provider, ''), COALESCE(OLD.tags, '[]'));\n INSERT INTO directory_agents_fts(rowid, id, name, description, provider, tags)\n VALUES (NEW.rowid, NEW.id, NEW.name, COALESCE(NEW.description, ''), COALESCE(NEW.provider, ''), COALESCE(NEW.tags, '[]'));\nEND",
|
|
123
|
+
"CREATE TRIGGER IF NOT EXISTS directory_agents_fts_delete\nAFTER DELETE ON directory_agents BEGIN\n INSERT INTO directory_agents_fts(directory_agents_fts, rowid, id, name, description, provider, tags)\n VALUES ('delete', OLD.rowid, OLD.id, OLD.name, COALESCE(OLD.description, ''), COALESCE(OLD.provider, ''), COALESCE(OLD.tags, '[]'));\nEND",
|
|
124
|
+
"CREATE VIRTUAL TABLE IF NOT EXISTS directory_skills_fts USING fts5(\n id UNINDEXED,\n directory_agent_id UNINDEXED,\n name,\n description,\n tags,\n content=directory_skills,\n content_rowid=rowid\n)",
|
|
125
|
+
"CREATE TRIGGER IF NOT EXISTS directory_skills_fts_insert\nAFTER INSERT ON directory_skills BEGIN\n INSERT INTO directory_skills_fts(rowid, id, directory_agent_id, name, description, tags)\n VALUES (NEW.rowid, NEW.id, NEW.directory_agent_id, NEW.name, COALESCE(NEW.description, ''), COALESCE(NEW.tags, '[]'));\nEND",
|
|
126
|
+
"CREATE TRIGGER IF NOT EXISTS directory_skills_fts_update\nAFTER UPDATE OF name, description, tags ON directory_skills BEGIN\n INSERT INTO directory_skills_fts(directory_skills_fts, rowid, id, directory_agent_id, name, description, tags)\n VALUES ('delete', OLD.rowid, OLD.id, OLD.directory_agent_id, OLD.name, COALESCE(OLD.description, ''), COALESCE(OLD.tags, '[]'));\n INSERT INTO directory_skills_fts(rowid, id, directory_agent_id, name, description, tags)\n VALUES (NEW.rowid, NEW.id, NEW.directory_agent_id, NEW.name, COALESCE(NEW.description, ''), COALESCE(NEW.tags, '[]'));\nEND",
|
|
127
|
+
"CREATE TRIGGER IF NOT EXISTS directory_skills_fts_delete\nAFTER DELETE ON directory_skills BEGIN\n INSERT INTO directory_skills_fts(directory_skills_fts, rowid, id, directory_agent_id, name, description, tags)\n VALUES ('delete', OLD.rowid, OLD.id, OLD.directory_agent_id, OLD.name, COALESCE(OLD.description, ''), COALESCE(OLD.tags, '[]'));\nEND"
|
|
128
|
+
]
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
"0008_smart_routing.sql",
|
|
132
|
+
[
|
|
133
|
+
"CREATE TABLE IF NOT EXISTS routing_configs (\n workspace_id TEXT PRIMARY KEY NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n weights TEXT NOT NULL DEFAULT '{}',\n circuit_breaker_threshold INTEGER NOT NULL DEFAULT 3,\n circuit_breaker_cooldown_seconds INTEGER NOT NULL DEFAULT 300,\n updated_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
134
|
+
"CREATE INDEX IF NOT EXISTS idx_routing_configs_updated_at\n ON routing_configs(updated_at)",
|
|
135
|
+
"CREATE TABLE IF NOT EXISTS routing_failures (\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,\n consecutive_failures INTEGER NOT NULL DEFAULT 0,\n total_failures INTEGER NOT NULL DEFAULT 0,\n total_successes INTEGER NOT NULL DEFAULT 0,\n last_failure_at INTEGER,\n last_success_at INTEGER,\n circuit_open_until INTEGER,\n last_error TEXT,\n updated_at INTEGER NOT NULL DEFAULT (unixepoch()),\n PRIMARY KEY (workspace_id, agent_id)\n)",
|
|
136
|
+
"CREATE INDEX IF NOT EXISTS idx_routing_failures_workspace\n ON routing_failures(workspace_id, updated_at)",
|
|
137
|
+
"CREATE INDEX IF NOT EXISTS idx_routing_failures_circuit\n ON routing_failures(workspace_id, circuit_open_until)"
|
|
138
|
+
]
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
"0009_drop_workspace_name_unique.sql",
|
|
142
|
+
[
|
|
143
|
+
"DROP INDEX IF EXISTS `workspaces_name_unique`"
|
|
144
|
+
]
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
"0010_actions_and_harness.sql",
|
|
148
|
+
[
|
|
149
|
+
"ALTER TABLE agents ADD COLUMN capabilities TEXT DEFAULT NULL",
|
|
150
|
+
"CREATE TABLE IF NOT EXISTS actions (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n name TEXT NOT NULL,\n description TEXT NOT NULL,\n handler_agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,\n input_schema TEXT DEFAULT '{}',\n output_schema TEXT DEFAULT '{}',\n available_to TEXT DEFAULT NULL,\n is_active INTEGER NOT NULL DEFAULT 1,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
151
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS actions_workspace_name_unique\n ON actions(workspace_id, name)",
|
|
152
|
+
"CREATE INDEX IF NOT EXISTS idx_actions_workspace\n ON actions(workspace_id)",
|
|
153
|
+
"CREATE INDEX IF NOT EXISTS idx_actions_handler\n ON actions(handler_agent_id)",
|
|
154
|
+
"INSERT OR IGNORE INTO actions (id, workspace_id, name, description, handler_agent_id, input_schema, is_active, created_at)\nSELECT id, workspace_id, command, description, handler_agent_id,\n COALESCE(parameters, '[]'), is_active, created_at\nFROM commands",
|
|
155
|
+
"DROP TABLE IF EXISTS commands",
|
|
156
|
+
"CREATE TABLE IF NOT EXISTS action_invocations (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n action_id TEXT REFERENCES actions(id) ON DELETE SET NULL,\n action_name TEXT NOT NULL,\n caller_id TEXT REFERENCES agents(id) ON DELETE SET NULL,\n caller_name TEXT,\n input TEXT DEFAULT '{}',\n output TEXT DEFAULT NULL,\n status TEXT NOT NULL DEFAULT 'invoked',\n error TEXT DEFAULT NULL,\n duration_ms INTEGER DEFAULT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n completed_at INTEGER DEFAULT NULL\n)",
|
|
157
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_workspace\n ON action_invocations(workspace_id, created_at)",
|
|
158
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_action\n ON action_invocations(action_id, created_at)",
|
|
159
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_caller\n ON action_invocations(caller_id, created_at)",
|
|
160
|
+
"CREATE TABLE IF NOT EXISTS session_events (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,\n type TEXT NOT NULL,\n payload TEXT NOT NULL DEFAULT '{}',\n sequence INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
161
|
+
"CREATE INDEX IF NOT EXISTS idx_session_events_agent\n ON session_events(agent_id, created_at)",
|
|
162
|
+
"CREATE INDEX IF NOT EXISTS idx_session_events_workspace\n ON session_events(workspace_id, created_at)",
|
|
163
|
+
"CREATE INDEX IF NOT EXISTS idx_session_events_type\n ON session_events(workspace_id, type, created_at)",
|
|
164
|
+
"CREATE TABLE IF NOT EXISTS deliveries (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n message_id TEXT NOT NULL REFERENCES messages(id) ON DELETE CASCADE,\n agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,\n mode TEXT NOT NULL DEFAULT 'immediate',\n reason TEXT,\n priority TEXT NOT NULL DEFAULT 'normal',\n deadline INTEGER DEFAULT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n retryable INTEGER DEFAULT NULL,\n available_at INTEGER DEFAULT NULL,\n error TEXT DEFAULT NULL,\n idempotency_key TEXT DEFAULT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n updated_at INTEGER DEFAULT NULL\n)",
|
|
165
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_message\n ON deliveries(message_id)",
|
|
166
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_agent\n ON deliveries(agent_id, created_at)",
|
|
167
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_status\n ON deliveries(workspace_id, status, created_at)"
|
|
168
|
+
]
|
|
169
|
+
],
|
|
170
|
+
[
|
|
171
|
+
"0011_stable_handle.sql",
|
|
172
|
+
[
|
|
173
|
+
"ALTER TABLE agents ADD COLUMN handle TEXT DEFAULT NULL",
|
|
174
|
+
"UPDATE agents SET handle = '@' || name WHERE handle IS NULL"
|
|
175
|
+
]
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
"0012_delivery_and_sequence_constraints.sql",
|
|
179
|
+
[
|
|
180
|
+
"DELETE FROM deliveries\nWHERE rowid NOT IN (\n SELECT MIN(rowid) FROM deliveries GROUP BY message_id, agent_id\n)",
|
|
181
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS deliveries_message_agent_unique\n ON deliveries(message_id, agent_id)",
|
|
182
|
+
"DELETE FROM session_events\nWHERE rowid NOT IN (\n SELECT MIN(rowid) FROM session_events GROUP BY agent_id, sequence\n)",
|
|
183
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS session_events_agent_sequence_unique\n ON session_events(agent_id, sequence)"
|
|
184
|
+
]
|
|
185
|
+
],
|
|
186
|
+
[
|
|
187
|
+
"0013_status_active.sql",
|
|
188
|
+
[
|
|
189
|
+
"UPDATE agents SET status = 'active' WHERE status = 'online'"
|
|
190
|
+
]
|
|
191
|
+
],
|
|
192
|
+
[
|
|
193
|
+
"0014_normalize_delivery_pending.sql",
|
|
194
|
+
[
|
|
195
|
+
"UPDATE deliveries SET status = 'accepted' WHERE status = 'pending'"
|
|
196
|
+
]
|
|
197
|
+
],
|
|
198
|
+
[
|
|
199
|
+
"0015_sdk_v8_contract.sql",
|
|
200
|
+
[
|
|
201
|
+
"ALTER TABLE webhooks ADD COLUMN token_hash TEXT DEFAULT NULL",
|
|
202
|
+
"CREATE INDEX IF NOT EXISTS idx_webhooks_token ON webhooks(token_hash)",
|
|
203
|
+
"ALTER TABLE event_subscriptions ADD COLUMN headers TEXT DEFAULT NULL"
|
|
204
|
+
]
|
|
205
|
+
],
|
|
206
|
+
[
|
|
207
|
+
"0016_fleet_nodes.sql",
|
|
208
|
+
[
|
|
209
|
+
"CREATE TABLE IF NOT EXISTS nodes (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n name TEXT NOT NULL,\n token_hash TEXT NOT NULL UNIQUE,\n capabilities TEXT NOT NULL DEFAULT '[]',\n max_agents INTEGER NOT NULL DEFAULT 0,\n active_agents INTEGER NOT NULL DEFAULT 0,\n tags TEXT NOT NULL DEFAULT '[]',\n version TEXT NOT NULL DEFAULT 'unknown',\n status TEXT NOT NULL DEFAULT 'offline',\n handlers_live INTEGER NOT NULL DEFAULT 0,\n load REAL NOT NULL DEFAULT 0,\n last_heartbeat_at INTEGER DEFAULT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
210
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS nodes_workspace_name_unique\n ON nodes(workspace_id, name)",
|
|
211
|
+
"CREATE INDEX IF NOT EXISTS idx_nodes_workspace\n ON nodes(workspace_id)",
|
|
212
|
+
"CREATE INDEX IF NOT EXISTS idx_nodes_token\n ON nodes(token_hash)",
|
|
213
|
+
"CREATE INDEX IF NOT EXISTS idx_nodes_status\n ON nodes(workspace_id, status)",
|
|
214
|
+
"ALTER TABLE agents ADD COLUMN location_type TEXT NOT NULL DEFAULT 'self_connected'",
|
|
215
|
+
"ALTER TABLE agents ADD COLUMN location_node_id TEXT DEFAULT NULL REFERENCES nodes(id) ON DELETE SET NULL",
|
|
216
|
+
"ALTER TABLE agents ADD COLUMN resumable INTEGER NOT NULL DEFAULT 0",
|
|
217
|
+
"ALTER TABLE agents ADD COLUMN session_ref TEXT DEFAULT NULL",
|
|
218
|
+
"ALTER TABLE agents ADD COLUMN origin_node_id TEXT DEFAULT NULL REFERENCES nodes(id) ON DELETE SET NULL",
|
|
219
|
+
"ALTER TABLE actions RENAME TO actions_0016_old",
|
|
220
|
+
"ALTER TABLE action_invocations RENAME TO action_invocations_0016_old",
|
|
221
|
+
"DROP INDEX IF EXISTS actions_workspace_name_unique",
|
|
222
|
+
"DROP INDEX IF EXISTS idx_actions_workspace",
|
|
223
|
+
"DROP INDEX IF EXISTS idx_actions_handler",
|
|
224
|
+
"DROP INDEX IF EXISTS idx_action_invocations_workspace",
|
|
225
|
+
"DROP INDEX IF EXISTS idx_action_invocations_action",
|
|
226
|
+
"DROP INDEX IF EXISTS idx_action_invocations_caller",
|
|
227
|
+
"CREATE TABLE actions (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n name TEXT NOT NULL,\n description TEXT NOT NULL,\n handler_agent_id TEXT REFERENCES agents(id) ON DELETE CASCADE,\n handler_node_id TEXT REFERENCES nodes(id) ON DELETE CASCADE,\n input_schema TEXT DEFAULT '{}',\n output_schema TEXT DEFAULT '{}',\n available_to TEXT DEFAULT NULL,\n is_active INTEGER NOT NULL DEFAULT 1,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
228
|
+
"INSERT INTO actions (\n id,\n workspace_id,\n name,\n description,\n handler_agent_id,\n handler_node_id,\n input_schema,\n output_schema,\n available_to,\n is_active,\n created_at\n)\nSELECT\n id,\n workspace_id,\n name,\n description,\n handler_agent_id,\n NULL,\n input_schema,\n output_schema,\n available_to,\n is_active,\n created_at\nFROM actions_0016_old",
|
|
229
|
+
"CREATE UNIQUE INDEX actions_workspace_name_unique\n ON actions(workspace_id, name)",
|
|
230
|
+
"CREATE INDEX idx_actions_workspace\n ON actions(workspace_id)",
|
|
231
|
+
"CREATE INDEX idx_actions_handler\n ON actions(handler_agent_id)",
|
|
232
|
+
"CREATE INDEX idx_actions_node_handler\n ON actions(handler_node_id)",
|
|
233
|
+
"CREATE TABLE action_invocations (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n action_id TEXT REFERENCES actions(id) ON DELETE SET NULL,\n action_name TEXT NOT NULL,\n caller_id TEXT REFERENCES agents(id) ON DELETE SET NULL,\n caller_name TEXT,\n input TEXT DEFAULT '{}',\n output TEXT DEFAULT NULL,\n status TEXT NOT NULL DEFAULT 'pending',\n error TEXT DEFAULT NULL,\n duration_ms INTEGER DEFAULT NULL,\n dispatched_node_id TEXT DEFAULT NULL REFERENCES nodes(id) ON DELETE SET NULL,\n dispatched_at INTEGER DEFAULT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n completed_at INTEGER DEFAULT NULL\n)",
|
|
234
|
+
"INSERT INTO action_invocations (\n id,\n workspace_id,\n action_id,\n action_name,\n caller_id,\n caller_name,\n input,\n output,\n status,\n error,\n duration_ms,\n dispatched_node_id,\n dispatched_at,\n created_at,\n completed_at\n)\nSELECT\n id,\n workspace_id,\n action_id,\n action_name,\n caller_id,\n caller_name,\n input,\n output,\n CASE WHEN status = 'invoked' THEN 'pending' ELSE status END,\n error,\n duration_ms,\n NULL,\n NULL,\n created_at,\n completed_at\nFROM action_invocations_0016_old",
|
|
235
|
+
"CREATE INDEX idx_action_invocations_workspace\n ON action_invocations(workspace_id, created_at)",
|
|
236
|
+
"CREATE INDEX idx_action_invocations_action\n ON action_invocations(action_id, created_at)",
|
|
237
|
+
"CREATE INDEX idx_action_invocations_caller\n ON action_invocations(caller_id, created_at)",
|
|
238
|
+
"CREATE INDEX idx_action_invocations_dispatched_node\n ON action_invocations(dispatched_node_id, created_at)",
|
|
239
|
+
"DROP TABLE action_invocations_0016_old",
|
|
240
|
+
"DROP TABLE actions_0016_old",
|
|
241
|
+
"CREATE TABLE IF NOT EXISTS triggers (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n channel TEXT DEFAULT NULL,\n pattern TEXT DEFAULT NULL,\n mention INTEGER DEFAULT NULL,\n action_name TEXT NOT NULL,\n enabled INTEGER NOT NULL DEFAULT 1,\n last_triggered_at INTEGER DEFAULT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n updated_at INTEGER DEFAULT NULL\n)",
|
|
242
|
+
"CREATE INDEX IF NOT EXISTS idx_triggers_workspace\n ON triggers(workspace_id)",
|
|
243
|
+
"CREATE INDEX IF NOT EXISTS idx_triggers_enabled\n ON triggers(workspace_id, enabled)",
|
|
244
|
+
"CREATE INDEX IF NOT EXISTS idx_triggers_action\n ON triggers(workspace_id, action_name)"
|
|
245
|
+
]
|
|
246
|
+
],
|
|
247
|
+
[
|
|
248
|
+
"0017_spawn_reservation_and_retry_state.sql",
|
|
249
|
+
[
|
|
250
|
+
"ALTER TABLE nodes ADD COLUMN reserved_agents INTEGER NOT NULL DEFAULT 0",
|
|
251
|
+
"ALTER TABLE action_invocations ADD COLUMN attempted_node_ids TEXT NOT NULL DEFAULT '[]'",
|
|
252
|
+
"ALTER TABLE action_invocations ADD COLUMN dispatch_attempts INTEGER NOT NULL DEFAULT 0",
|
|
253
|
+
"ALTER TABLE action_invocations ADD COLUMN retry_after_at INTEGER DEFAULT NULL"
|
|
254
|
+
]
|
|
255
|
+
],
|
|
256
|
+
[
|
|
257
|
+
"0018_spawn_reserved_at.sql",
|
|
258
|
+
[
|
|
259
|
+
"ALTER TABLE action_invocations ADD COLUMN spawn_reserved_at INTEGER DEFAULT NULL"
|
|
260
|
+
]
|
|
261
|
+
],
|
|
262
|
+
[
|
|
263
|
+
"0019_fleet_mailbox.sql",
|
|
264
|
+
[
|
|
265
|
+
"ALTER TABLE agents ADD COLUMN delivery_ack_seq INTEGER NOT NULL DEFAULT 0",
|
|
266
|
+
"ALTER TABLE deliveries ADD COLUMN seq INTEGER NOT NULL DEFAULT 0",
|
|
267
|
+
"ALTER TABLE deliveries ADD COLUMN location_type TEXT NOT NULL DEFAULT 'self_connected'",
|
|
268
|
+
"ALTER TABLE deliveries ADD COLUMN location_node_id TEXT DEFAULT NULL REFERENCES nodes(id) ON DELETE SET NULL",
|
|
269
|
+
"ALTER TABLE deliveries ADD COLUMN expires_at INTEGER DEFAULT NULL",
|
|
270
|
+
"ALTER TABLE deliveries ADD COLUMN delivered_at INTEGER DEFAULT NULL",
|
|
271
|
+
"ALTER TABLE deliveries ADD COLUMN acked_at INTEGER DEFAULT NULL",
|
|
272
|
+
"ALTER TABLE deliveries ADD COLUMN dead_lettered_at INTEGER DEFAULT NULL",
|
|
273
|
+
"UPDATE deliveries SET status = 'queued' WHERE status IN ('pending', 'accepted', 'deferred')",
|
|
274
|
+
"UPDATE deliveries SET status = 'acked', acked_at = COALESCE(updated_at, created_at) WHERE status = 'delivered'",
|
|
275
|
+
"UPDATE deliveries\nSET\n location_type = COALESCE((SELECT location_type FROM agents WHERE agents.id = deliveries.agent_id), 'self_connected'),\n location_node_id = (SELECT location_node_id FROM agents WHERE agents.id = deliveries.agent_id)",
|
|
276
|
+
"WITH ranked AS (\n SELECT\n rowid AS rid,\n ROW_NUMBER() OVER (\n PARTITION BY workspace_id, agent_id\n ORDER BY created_at, id\n ) AS rn\n FROM deliveries\n)\nUPDATE deliveries\nSET seq = (SELECT rn FROM ranked WHERE ranked.rid = deliveries.rowid)",
|
|
277
|
+
"UPDATE deliveries\nSET expires_at = COALESCE(deadline, created_at + 3600)\nWHERE status IN ('queued', 'delivered') AND expires_at IS NULL",
|
|
278
|
+
"UPDATE agents\nSET delivery_ack_seq = COALESCE(\n (\n SELECT MIN(seq) - 1\n FROM deliveries\n WHERE deliveries.agent_id = agents.id\n AND deliveries.status IN ('queued', 'delivered')\n ),\n (\n SELECT MAX(seq)\n FROM deliveries\n WHERE deliveries.agent_id = agents.id\n ),\n 0\n)",
|
|
279
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS deliveries_agent_seq_unique\n ON deliveries(workspace_id, agent_id, seq)",
|
|
280
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_agent_status_seq\n ON deliveries(workspace_id, agent_id, status, seq)",
|
|
281
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_expires\n ON deliveries(workspace_id, status, expires_at)"
|
|
282
|
+
]
|
|
283
|
+
],
|
|
284
|
+
[
|
|
285
|
+
"0020_workspace_retention.sql",
|
|
286
|
+
[
|
|
287
|
+
"ALTER TABLE workspaces ADD COLUMN retention text"
|
|
288
|
+
]
|
|
289
|
+
],
|
|
290
|
+
[
|
|
291
|
+
"0021_node_delivery_contracts.sql",
|
|
292
|
+
[
|
|
293
|
+
"ALTER TABLE nodes ADD COLUMN kind TEXT NOT NULL DEFAULT 'fleet_ws'",
|
|
294
|
+
"ALTER TABLE nodes ADD COLUMN delivery_adapter TEXT NOT NULL DEFAULT 'fleet.ws.v1'",
|
|
295
|
+
"ALTER TABLE nodes ADD COLUMN delivery_config TEXT DEFAULT NULL",
|
|
296
|
+
"CREATE TABLE IF NOT EXISTS agent_node_bindings (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,\n node_id TEXT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,\n status TEXT NOT NULL DEFAULT 'active',\n session_ref TEXT,\n priority INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n updated_at INTEGER,\n UNIQUE(agent_id, node_id)\n)",
|
|
297
|
+
"CREATE INDEX IF NOT EXISTS idx_agent_node_bindings_workspace\n ON agent_node_bindings(workspace_id, status)",
|
|
298
|
+
"CREATE INDEX IF NOT EXISTS idx_agent_node_bindings_agent\n ON agent_node_bindings(workspace_id, agent_id, status)",
|
|
299
|
+
"CREATE INDEX IF NOT EXISTS idx_agent_node_bindings_node\n ON agent_node_bindings(workspace_id, node_id, status)",
|
|
300
|
+
"INSERT OR IGNORE INTO agent_node_bindings (\n id,\n workspace_id,\n agent_id,\n node_id,\n status,\n session_ref,\n priority,\n created_at\n)\nSELECT\n 'anb_' || id,\n workspace_id,\n id,\n location_node_id,\n 'active',\n session_ref,\n 0,\n unixepoch()\nFROM agents\nWHERE location_type = 'via_node'\n AND location_node_id IS NOT NULL",
|
|
301
|
+
"ALTER TABLE deliveries ADD COLUMN route_node_id TEXT DEFAULT NULL REFERENCES nodes(id) ON DELETE SET NULL",
|
|
302
|
+
"ALTER TABLE deliveries ADD COLUMN route_node_kind TEXT DEFAULT NULL",
|
|
303
|
+
"ALTER TABLE deliveries ADD COLUMN delivery_adapter TEXT DEFAULT NULL",
|
|
304
|
+
"ALTER TABLE deliveries ADD COLUMN dispatch_attempts INTEGER NOT NULL DEFAULT 0",
|
|
305
|
+
"ALTER TABLE deliveries ADD COLUMN next_attempt_at INTEGER DEFAULT NULL",
|
|
306
|
+
"ALTER TABLE deliveries ADD COLUMN last_dispatch_error TEXT DEFAULT NULL",
|
|
307
|
+
"UPDATE deliveries\nSET\n route_node_id = location_node_id,\n route_node_kind = CASE WHEN location_node_id IS NOT NULL THEN 'fleet_ws' ELSE NULL END,\n delivery_adapter = CASE WHEN location_node_id IS NOT NULL THEN 'fleet.ws.v1' ELSE NULL END",
|
|
308
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_route_node\n ON deliveries(workspace_id, route_node_id, status, seq)",
|
|
309
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_next_attempt\n ON deliveries(workspace_id, status, next_attempt_at)"
|
|
310
|
+
]
|
|
311
|
+
],
|
|
312
|
+
[
|
|
313
|
+
"0022_http_push_redrive.sql",
|
|
314
|
+
[
|
|
315
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_http_push_due\n ON deliveries(workspace_id, route_node_kind, status, next_attempt_at)",
|
|
316
|
+
"UPDATE nodes\nSET active_agents = (\n SELECT COUNT(*)\n FROM agent_node_bindings b\n WHERE b.workspace_id = nodes.workspace_id\n AND b.node_id = nodes.id\n AND b.status = 'active'\n)"
|
|
317
|
+
]
|
|
318
|
+
],
|
|
319
|
+
[
|
|
320
|
+
"0023_direct_ws_nodes.sql",
|
|
321
|
+
[
|
|
322
|
+
"INSERT OR IGNORE INTO nodes (\n id,\n workspace_id,\n name,\n token_hash,\n kind,\n delivery_adapter,\n delivery_config,\n capabilities,\n max_agents,\n active_agents,\n reserved_agents,\n tags,\n version,\n status,\n handlers_live,\n load,\n last_heartbeat_at,\n created_at\n)\nSELECT\n 'node_direct_' || a.id,\n a.workspace_id,\n 'direct-' || a.id,\n 'implicit_direct:' || a.workspace_id || ':' || a.id,\n 'direct_ws',\n 'direct.ws.v1',\n json_object('implicit', 1, 'agent_id', a.id, 'agent_name', a.name),\n json_array(),\n 1,\n 1,\n 0,\n json_array('implicit', 'direct_ws'),\n 'implicit',\n CASE WHEN a.status IN ('active', 'online') THEN 'online' ELSE 'offline' END,\n 0,\n 0,\n CASE WHEN a.status IN ('active', 'online') THEN unixepoch() ELSE NULL END,\n unixepoch()\nFROM agents a\nWHERE NOT EXISTS (\n SELECT 1\n FROM agent_node_bindings b\n WHERE b.workspace_id = a.workspace_id\n AND b.agent_id = a.id\n AND b.status = 'active'\n)",
|
|
323
|
+
"INSERT OR IGNORE INTO agent_node_bindings (\n id,\n workspace_id,\n agent_id,\n node_id,\n status,\n session_ref,\n priority,\n created_at,\n updated_at\n)\nSELECT\n 'anb_direct_' || a.id,\n a.workspace_id,\n a.id,\n 'node_direct_' || a.id,\n 'active',\n a.session_ref,\n 0,\n unixepoch(),\n unixepoch()\nFROM agents a\nWHERE EXISTS (\n SELECT 1\n FROM nodes n\n WHERE n.workspace_id = a.workspace_id\n AND n.id = 'node_direct_' || a.id\n AND n.kind = 'direct_ws'\n)\n AND NOT EXISTS (\n SELECT 1\n FROM agent_node_bindings b\n WHERE b.workspace_id = a.workspace_id\n AND b.agent_id = a.id\n AND b.status = 'active'\n )",
|
|
324
|
+
"UPDATE agents\nSET\n location_type = 'via_node',\n location_node_id = 'node_direct_' || id,\n origin_node_id = COALESCE(origin_node_id, 'node_direct_' || id)\nWHERE EXISTS (\n SELECT 1\n FROM agent_node_bindings b\n WHERE b.workspace_id = agents.workspace_id\n AND b.agent_id = agents.id\n AND b.node_id = 'node_direct_' || agents.id\n AND b.status = 'active'\n)",
|
|
325
|
+
"UPDATE deliveries\nSET\n route_node_id = 'node_direct_' || agent_id,\n route_node_kind = 'direct_ws',\n delivery_adapter = 'direct.ws.v1'\nWHERE route_node_id IS NULL\n AND EXISTS (\n SELECT 1\n FROM agents a\n WHERE a.workspace_id = deliveries.workspace_id\n AND a.id = deliveries.agent_id\n AND a.location_node_id = 'node_direct_' || a.id\n )",
|
|
326
|
+
"UPDATE nodes\nSET active_agents = (\n SELECT COUNT(*)\n FROM agent_node_bindings b\n WHERE b.workspace_id = nodes.workspace_id\n AND b.node_id = nodes.id\n AND b.status = 'active'\n)"
|
|
327
|
+
]
|
|
328
|
+
],
|
|
329
|
+
[
|
|
330
|
+
"0024_binding_workspace_constraints.sql",
|
|
331
|
+
[
|
|
332
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS agents_workspace_id_unique\n ON agents(workspace_id, id)",
|
|
333
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS nodes_workspace_id_unique\n ON nodes(workspace_id, id)",
|
|
334
|
+
"CREATE TABLE IF NOT EXISTS agent_node_bindings_constrained (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n agent_id TEXT NOT NULL REFERENCES agents(id) ON DELETE CASCADE,\n node_id TEXT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,\n status TEXT NOT NULL DEFAULT 'active',\n session_ref TEXT,\n priority INTEGER NOT NULL DEFAULT 0,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n updated_at INTEGER,\n FOREIGN KEY(workspace_id, agent_id) REFERENCES agents(workspace_id, id) ON DELETE CASCADE,\n FOREIGN KEY(workspace_id, node_id) REFERENCES nodes(workspace_id, id) ON DELETE CASCADE,\n UNIQUE(agent_id, node_id)\n)",
|
|
335
|
+
"INSERT OR IGNORE INTO agent_node_bindings_constrained (\n id,\n workspace_id,\n agent_id,\n node_id,\n status,\n session_ref,\n priority,\n created_at,\n updated_at\n)\nSELECT\n b.id,\n b.workspace_id,\n b.agent_id,\n b.node_id,\n b.status,\n b.session_ref,\n b.priority,\n b.created_at,\n b.updated_at\nFROM agent_node_bindings b\nINNER JOIN agents a\n ON a.workspace_id = b.workspace_id\n AND a.id = b.agent_id\nINNER JOIN nodes n\n ON n.workspace_id = b.workspace_id\n AND n.id = b.node_id",
|
|
336
|
+
"DROP TABLE agent_node_bindings",
|
|
337
|
+
"ALTER TABLE agent_node_bindings_constrained RENAME TO agent_node_bindings",
|
|
338
|
+
"CREATE INDEX IF NOT EXISTS idx_agent_node_bindings_workspace\n ON agent_node_bindings(workspace_id, status)",
|
|
339
|
+
"CREATE INDEX IF NOT EXISTS idx_agent_node_bindings_agent\n ON agent_node_bindings(workspace_id, agent_id, status)",
|
|
340
|
+
"CREATE INDEX IF NOT EXISTS idx_agent_node_bindings_node\n ON agent_node_bindings(workspace_id, node_id, status)",
|
|
341
|
+
"CREATE TRIGGER IF NOT EXISTS agent_node_bindings_workspace_agent_insert\nBEFORE INSERT ON agent_node_bindings\nWHEN NOT EXISTS (\n SELECT 1 FROM agents a\n WHERE a.workspace_id = NEW.workspace_id\n AND a.id = NEW.agent_id\n)\nBEGIN\n SELECT RAISE(ABORT, 'agent_node_bindings workspace/agent mismatch');\nEND",
|
|
342
|
+
"CREATE TRIGGER IF NOT EXISTS agent_node_bindings_workspace_node_insert\nBEFORE INSERT ON agent_node_bindings\nWHEN NOT EXISTS (\n SELECT 1 FROM nodes n\n WHERE n.workspace_id = NEW.workspace_id\n AND n.id = NEW.node_id\n)\nBEGIN\n SELECT RAISE(ABORT, 'agent_node_bindings workspace/node mismatch');\nEND",
|
|
343
|
+
"CREATE TRIGGER IF NOT EXISTS agent_node_bindings_workspace_agent_update\nBEFORE UPDATE OF workspace_id, agent_id ON agent_node_bindings\nWHEN NOT EXISTS (\n SELECT 1 FROM agents a\n WHERE a.workspace_id = NEW.workspace_id\n AND a.id = NEW.agent_id\n)\nBEGIN\n SELECT RAISE(ABORT, 'agent_node_bindings workspace/agent mismatch');\nEND",
|
|
344
|
+
"CREATE TRIGGER IF NOT EXISTS agent_node_bindings_workspace_node_update\nBEFORE UPDATE OF workspace_id, node_id ON agent_node_bindings\nWHEN NOT EXISTS (\n SELECT 1 FROM nodes n\n WHERE n.workspace_id = NEW.workspace_id\n AND n.id = NEW.node_id\n)\nBEGIN\n SELECT RAISE(ABORT, 'agent_node_bindings workspace/node mismatch');\nEND"
|
|
345
|
+
]
|
|
346
|
+
],
|
|
347
|
+
[
|
|
348
|
+
"0025_node_kind_role_adapter.sql",
|
|
349
|
+
[
|
|
350
|
+
"ALTER TABLE nodes ADD COLUMN role TEXT NOT NULL DEFAULT 'broker'",
|
|
351
|
+
"ALTER TABLE deliveries ADD COLUMN route_node_role TEXT DEFAULT NULL",
|
|
352
|
+
"UPDATE nodes\nSET\n role = CASE\n WHEN kind = 'direct_ws' THEN 'direct'\n WHEN kind = 'fleet_ws' THEN 'broker'\n WHEN kind = 'http_push' AND max_agents = 1 THEN 'direct'\n WHEN kind = 'http_push' THEN 'broker'\n ELSE role\n END,\n kind = CASE\n WHEN kind IN ('direct_ws', 'fleet_ws') THEN 'ws'\n ELSE kind\n END,\n delivery_adapter = CASE\n WHEN delivery_adapter IN ('direct.ws.v1', 'fleet.ws.v1') THEN 'ws.node.v1'\n ELSE delivery_adapter\n END",
|
|
353
|
+
"UPDATE deliveries\nSET\n route_node_role = CASE\n WHEN route_node_kind = 'direct_ws' THEN 'direct'\n WHEN route_node_kind = 'fleet_ws' THEN 'broker'\n WHEN route_node_id IS NOT NULL THEN (\n SELECT n.role\n FROM nodes n\n WHERE n.workspace_id = deliveries.workspace_id\n AND n.id = deliveries.route_node_id\n )\n ELSE NULL\n END,\n route_node_kind = CASE\n WHEN route_node_kind IN ('direct_ws', 'fleet_ws') THEN 'ws'\n ELSE route_node_kind\n END,\n delivery_adapter = CASE\n WHEN delivery_adapter IN ('direct.ws.v1', 'fleet.ws.v1') THEN 'ws.node.v1'\n ELSE delivery_adapter\n END"
|
|
354
|
+
]
|
|
355
|
+
],
|
|
356
|
+
[
|
|
357
|
+
"0026_observer_tokens.sql",
|
|
358
|
+
[
|
|
359
|
+
"CREATE TABLE observer_tokens (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL,\n name TEXT NOT NULL,\n description TEXT,\n token_hash TEXT NOT NULL,\n scopes TEXT NOT NULL DEFAULT '[]',\n filters TEXT NOT NULL DEFAULT '{}',\n status TEXT NOT NULL DEFAULT 'active',\n expires_at INTEGER,\n created_by TEXT,\n created_by_type TEXT NOT NULL DEFAULT 'workspace',\n last_used_at INTEGER,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n updated_at INTEGER,\n revoked_at INTEGER,\n FOREIGN KEY (workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE\n)",
|
|
360
|
+
"CREATE UNIQUE INDEX observer_tokens_workspace_name_unique\n ON observer_tokens (workspace_id, name)",
|
|
361
|
+
"CREATE UNIQUE INDEX observer_tokens_token_hash_unique\n ON observer_tokens (token_hash)",
|
|
362
|
+
"CREATE INDEX idx_observer_tokens_workspace_status\n ON observer_tokens (workspace_id, status)",
|
|
363
|
+
"CREATE INDEX idx_observer_tokens_expires_at\n ON observer_tokens (expires_at)"
|
|
364
|
+
]
|
|
365
|
+
],
|
|
366
|
+
[
|
|
367
|
+
"0027_workspace_event_log.sql",
|
|
368
|
+
[
|
|
369
|
+
"CREATE TABLE workspace_events (\n workspace_id TEXT NOT NULL,\n seq INTEGER NOT NULL CHECK (seq > 0),\n type TEXT NOT NULL,\n channel_id TEXT,\n payload TEXT NOT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n PRIMARY KEY (workspace_id, seq)\n)",
|
|
370
|
+
"CREATE INDEX idx_workspace_events_created ON workspace_events(workspace_id, created_at)"
|
|
371
|
+
]
|
|
372
|
+
],
|
|
373
|
+
[
|
|
374
|
+
"0028_node_providers.sql",
|
|
375
|
+
[
|
|
376
|
+
"ALTER TABLE nodes ADD COLUMN machine_id TEXT DEFAULT NULL",
|
|
377
|
+
"ALTER TABLE agents ADD COLUMN provider_name TEXT NOT NULL DEFAULT 'default'",
|
|
378
|
+
"ALTER TABLE actions ADD COLUMN handler_provider TEXT DEFAULT NULL",
|
|
379
|
+
"ALTER TABLE actions ADD COLUMN is_global INTEGER NOT NULL DEFAULT 0",
|
|
380
|
+
"ALTER TABLE actions ADD COLUMN queue INTEGER NOT NULL DEFAULT 0",
|
|
381
|
+
"CREATE TABLE node_providers (\n id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n node_id TEXT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,\n name TEXT NOT NULL,\n instance_id TEXT NOT NULL,\n capabilities TEXT NOT NULL DEFAULT '[]',\n max_agents INTEGER NOT NULL DEFAULT 0,\n active_agents INTEGER NOT NULL DEFAULT 0,\n load REAL NOT NULL DEFAULT 0,\n handlers_live INTEGER NOT NULL DEFAULT 0,\n status TEXT NOT NULL DEFAULT 'offline',\n version TEXT NOT NULL DEFAULT 'unknown',\n last_heartbeat_at INTEGER DEFAULT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
382
|
+
"CREATE UNIQUE INDEX node_providers_node_name_unique ON node_providers (workspace_id, node_id, name)",
|
|
383
|
+
"CREATE INDEX idx_node_providers_node ON node_providers (workspace_id, node_id)",
|
|
384
|
+
"UPDATE actions SET handler_provider = 'default', is_global = 1 WHERE handler_node_id IS NOT NULL",
|
|
385
|
+
"INSERT INTO node_providers (\n id, workspace_id, node_id, name, instance_id, capabilities,\n max_agents, active_agents, load, handlers_live, status, version, last_heartbeat_at, created_at\n)\nSELECT\n 'nprov_' || id, workspace_id, id, 'default', 'migrated', capabilities,\n max_agents, active_agents, load, handlers_live, status, version, last_heartbeat_at, created_at\nFROM nodes\nWHERE role = 'broker'",
|
|
386
|
+
"DROP INDEX IF EXISTS actions_workspace_name_unique",
|
|
387
|
+
"CREATE UNIQUE INDEX actions_workspace_node_name_unique ON actions (workspace_id, handler_node_id, name)",
|
|
388
|
+
"CREATE UNIQUE INDEX actions_workspace_agent_name_unique ON actions (workspace_id, name) WHERE handler_node_id IS NULL",
|
|
389
|
+
"CREATE UNIQUE INDEX actions_workspace_global_name_unique ON actions (workspace_id, name) WHERE is_global = 1"
|
|
390
|
+
]
|
|
391
|
+
],
|
|
392
|
+
[
|
|
393
|
+
"0029_delivery_sequence_high_water.sql",
|
|
394
|
+
[
|
|
395
|
+
"ALTER TABLE agents ADD COLUMN delivery_seq INTEGER NOT NULL DEFAULT 0",
|
|
396
|
+
"WITH affected_agents AS MATERIALIZED (\n SELECT\n a.workspace_id,\n a.id AS agent_id,\n MAX(\n a.delivery_ack_seq,\n COALESCE((\n SELECT MAX(all_deliveries.seq)\n FROM deliveries all_deliveries\n WHERE all_deliveries.workspace_id = a.workspace_id\n AND all_deliveries.agent_id = a.id\n ), 0)\n ) AS base_seq\n FROM agents a\n WHERE EXISTS (\n SELECT 1\n FROM deliveries hidden\n WHERE hidden.workspace_id = a.workspace_id\n AND hidden.agent_id = a.id\n AND hidden.status IN ('queued', 'delivered')\n AND hidden.seq <= a.delivery_ack_seq\n )\n),\nranked_active AS MATERIALIZED (\n SELECT\n active.id,\n affected_agents.base_seq + ROW_NUMBER() OVER (\n PARTITION BY active.workspace_id, active.agent_id\n ORDER BY active.created_at, active.id\n ) AS repaired_seq\n FROM deliveries active\n INNER JOIN affected_agents\n ON affected_agents.workspace_id = active.workspace_id\n AND affected_agents.agent_id = active.agent_id\n WHERE active.status IN ('queued', 'delivered')\n)\nUPDATE deliveries\nSET seq = (\n SELECT ranked_active.repaired_seq\n FROM ranked_active\n WHERE ranked_active.id = deliveries.id\n)\nWHERE id IN (SELECT id FROM ranked_active)",
|
|
397
|
+
"UPDATE agents\nSET delivery_seq = MAX(\n delivery_ack_seq,\n COALESCE((\n SELECT MAX(deliveries.seq)\n FROM deliveries\n WHERE deliveries.workspace_id = agents.workspace_id\n AND deliveries.agent_id = agents.id\n ), 0)\n)",
|
|
398
|
+
"CREATE TRIGGER deliveries_advance_sequence_high_water\nAFTER INSERT ON deliveries\nBEGIN\n UPDATE agents\n SET delivery_seq = MAX(delivery_seq, NEW.seq)\n WHERE id = NEW.agent_id\n AND workspace_id = NEW.workspace_id;\nEND"
|
|
399
|
+
]
|
|
400
|
+
],
|
|
401
|
+
[
|
|
402
|
+
"0030_action_invocation_provider.sql",
|
|
403
|
+
[
|
|
404
|
+
"ALTER TABLE action_invocations ADD COLUMN dispatched_provider TEXT DEFAULT NULL",
|
|
405
|
+
"WITH spawn_targets AS (\n SELECT\n id AS invocation_id,\n workspace_id,\n dispatched_node_id,\n CASE\n WHEN json_type(input, '$.capability') = 'text'\n AND NULLIF(trim(json_extract(input, '$.capability')), '') IS NOT NULL\n THEN CASE\n WHEN trim(json_extract(input, '$.capability')) LIKE 'spawn:%'\n THEN trim(json_extract(input, '$.capability'))\n ELSE 'spawn:' || trim(json_extract(input, '$.capability'))\n END\n WHEN json_type(input, '$.cli') = 'text'\n AND NULLIF(trim(json_extract(input, '$.cli')), '') IS NOT NULL\n THEN CASE\n WHEN trim(json_extract(input, '$.cli')) LIKE 'spawn:%'\n THEN trim(json_extract(input, '$.cli'))\n ELSE 'spawn:' || trim(json_extract(input, '$.cli'))\n END\n ELSE action_name\n END AS capability_name\n FROM action_invocations\n WHERE dispatched_node_id IS NOT NULL\n AND action_name LIKE 'spawn%'\n),\nspawn_candidates AS (\n SELECT spawn_targets.invocation_id, actions.handler_provider AS provider_name\n FROM spawn_targets\n JOIN actions\n ON actions.workspace_id = spawn_targets.workspace_id\n AND actions.handler_node_id = spawn_targets.dispatched_node_id\n AND actions.name = spawn_targets.capability_name\n WHERE actions.handler_provider IS NOT NULL\n\n UNION ALL\n\n SELECT spawn_targets.invocation_id, node_providers.name AS provider_name\n FROM spawn_targets\n JOIN node_providers\n ON node_providers.workspace_id = spawn_targets.workspace_id\n AND node_providers.node_id = spawn_targets.dispatched_node_id\n JOIN json_each(node_providers.capabilities) AS capability\n WHERE CASE\n WHEN capability.type = 'text' THEN capability.value\n ELSE json_extract(capability.value, '$.name')\n END = spawn_targets.capability_name\n AND CASE\n WHEN capability.type = 'text' THEN 'capacity'\n ELSE COALESCE(json_extract(capability.value, '$.kind'), 'capacity')\n END = 'capacity'\n),\nspawn_owners AS (\n SELECT\n invocation_id,\n CASE WHEN COUNT(DISTINCT provider_name) = 1 THEN MIN(provider_name) END AS provider_name\n FROM spawn_candidates\n GROUP BY invocation_id\n)\nUPDATE action_invocations\nSET dispatched_provider = COALESCE(\n (SELECT actions.handler_provider FROM actions WHERE actions.id = action_invocations.action_id),\n (\n SELECT agents.provider_name\n FROM actions\n JOIN agents ON agents.id = actions.handler_agent_id\n WHERE actions.id = action_invocations.action_id\n ),\n (\n SELECT agents.provider_name\n FROM agents\n WHERE action_invocations.action_name = 'release'\n AND agents.workspace_id = action_invocations.workspace_id\n AND agents.name = json_extract(action_invocations.input, '$.name')\n LIMIT 1\n ),\n (\n SELECT spawn_owners.provider_name\n FROM spawn_owners\n WHERE spawn_owners.invocation_id = action_invocations.id\n ),\n (\n SELECT CASE WHEN COUNT(*) = 1 THEN MIN(node_providers.name) END\n FROM node_providers\n WHERE node_providers.workspace_id = action_invocations.workspace_id\n AND node_providers.node_id = action_invocations.dispatched_node_id\n AND NOT EXISTS (\n SELECT 1\n FROM spawn_candidates\n WHERE spawn_candidates.invocation_id = action_invocations.id\n )\n )\n)\nWHERE dispatched_node_id IS NOT NULL"
|
|
406
|
+
]
|
|
407
|
+
],
|
|
408
|
+
[
|
|
409
|
+
"0031_delivery_active_expiry_index.sql",
|
|
410
|
+
[
|
|
411
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_active_expiry\n ON deliveries(expires_at, id)\n WHERE status IN ('queued', 'delivered') AND expires_at IS NOT NULL"
|
|
412
|
+
]
|
|
413
|
+
],
|
|
414
|
+
[
|
|
415
|
+
"0032_invocation_handler_unreachable.sql",
|
|
416
|
+
[
|
|
417
|
+
"ALTER TABLE action_invocations ADD COLUMN handler_unreachable_since INTEGER"
|
|
418
|
+
]
|
|
419
|
+
],
|
|
420
|
+
[
|
|
421
|
+
"0033_dm_conversation_reservations.sql",
|
|
422
|
+
[
|
|
423
|
+
"CREATE TABLE dm_conversation_reservations (\n conversation_id TEXT PRIMARY KEY,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n participant_one_id TEXT NOT NULL,\n participant_two_id TEXT NOT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n CONSTRAINT dm_conversation_reservations_sorted_pair_check\n CHECK (participant_one_id <= participant_two_id)\n)",
|
|
424
|
+
"CREATE UNIQUE INDEX dm_conversation_reservations_pair_unique\n ON dm_conversation_reservations (workspace_id, participant_one_id, participant_two_id)",
|
|
425
|
+
"INSERT INTO dm_conversation_reservations (\n conversation_id,\n workspace_id,\n participant_one_id,\n participant_two_id,\n created_at\n)\nSELECT\n dc.id,\n dc.workspace_id,\n MIN(dp.agent_id),\n MAX(dp.agent_id),\n dc.created_at\nFROM dm_conversations dc\nJOIN dm_participants dp ON dp.conversation_id = dc.id\nWHERE dc.dm_type = '1:1'\nGROUP BY dc.id, dc.workspace_id, dc.created_at\nHAVING COUNT(DISTINCT dp.agent_id) = 2"
|
|
426
|
+
]
|
|
427
|
+
],
|
|
428
|
+
[
|
|
429
|
+
"0034_node_load_reporting.sql",
|
|
430
|
+
[
|
|
431
|
+
"ALTER TABLE nodes ADD COLUMN load_reported INTEGER NOT NULL DEFAULT 0",
|
|
432
|
+
"ALTER TABLE node_providers ADD COLUMN load_reported INTEGER NOT NULL DEFAULT 0",
|
|
433
|
+
"UPDATE nodes\nSET max_agents = 0\nWHERE role = 'broker'\n AND EXISTS (\n SELECT 1\n FROM node_providers\n WHERE node_providers.workspace_id = nodes.workspace_id\n AND node_providers.node_id = nodes.id\n AND node_providers.max_agents = 0\n)"
|
|
434
|
+
]
|
|
435
|
+
],
|
|
436
|
+
[
|
|
437
|
+
"0035_agent_token_grace.sql",
|
|
438
|
+
[
|
|
439
|
+
"ALTER TABLE agents ADD COLUMN previous_token_hash TEXT",
|
|
440
|
+
"ALTER TABLE agents ADD COLUMN previous_token_expires_at INTEGER",
|
|
441
|
+
"CREATE INDEX IF NOT EXISTS idx_agents_previous_token ON agents(previous_token_hash)"
|
|
442
|
+
]
|
|
443
|
+
],
|
|
444
|
+
[
|
|
445
|
+
"0036_workspace_expiry.sql",
|
|
446
|
+
[
|
|
447
|
+
"ALTER TABLE `workspaces` ADD `expires_at` integer",
|
|
448
|
+
"CREATE INDEX `idx_workspaces_expires_at` ON `workspaces` (`expires_at`)"
|
|
449
|
+
]
|
|
450
|
+
],
|
|
451
|
+
[
|
|
452
|
+
"0037_file_cleanup_outbox.sql",
|
|
453
|
+
[
|
|
454
|
+
"ALTER TABLE `files` ADD `upload_expires_at` integer",
|
|
455
|
+
"CREATE TABLE `file_cleanup_queue` (\n `storage_key` text PRIMARY KEY NOT NULL,\n `delete_after` integer NOT NULL,\n `process_after` integer DEFAULT (unixepoch()) NOT NULL,\n `attempts` integer DEFAULT 0 NOT NULL,\n `last_error` text,\n `created_at` integer DEFAULT (unixepoch()) NOT NULL\n)",
|
|
456
|
+
"CREATE INDEX `idx_file_cleanup_due`\n ON `file_cleanup_queue` (`process_after`, `storage_key`)",
|
|
457
|
+
"CREATE TRIGGER `files_enqueue_object_cleanup`\nAFTER DELETE ON `files`\nBEGIN\n INSERT INTO `file_cleanup_queue` (`storage_key`, `delete_after`)\n VALUES (\n OLD.`storage_key`,\n MAX(unixepoch(), COALESCE(OLD.`upload_expires_at`, unixepoch() + 3600))\n )\n ON CONFLICT (`storage_key`) DO UPDATE SET\n `delete_after` = MAX(`file_cleanup_queue`.`delete_after`, excluded.`delete_after`);\nEND"
|
|
458
|
+
]
|
|
459
|
+
],
|
|
460
|
+
[
|
|
461
|
+
"0038_session_ref_lookup.sql",
|
|
462
|
+
[
|
|
463
|
+
"ALTER TABLE messages ADD COLUMN session_ref TEXT",
|
|
464
|
+
"CREATE INDEX idx_messages_workspace_session\n ON messages(workspace_id, session_ref, length(id), id)",
|
|
465
|
+
"CREATE TABLE message_sessions (\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n session_ref TEXT NOT NULL,\n first_message_at INTEGER NOT NULL,\n last_message_at INTEGER NOT NULL,\n start_is_known INTEGER NOT NULL DEFAULT 1 CHECK (start_is_known IN (0, 1)),\n PRIMARY KEY (workspace_id, session_ref)\n)",
|
|
466
|
+
"CREATE INDEX idx_message_sessions_workspace_last\n ON message_sessions(workspace_id, last_message_at)",
|
|
467
|
+
"UPDATE messages\nSET session_ref = json_extract(metadata, '$.session_ref')\nWHERE metadata IS NOT NULL\n AND json_valid(metadata)\n AND json_type(metadata, '$.session_ref') = 'text'\n AND length(json_extract(metadata, '$.session_ref')) BETWEEN 1 AND 255\n AND (\n COALESCE(json_extract(metadata, '$.__relaycast_origin'), '') <> 'inbound_webhook'\n OR EXISTS (\n SELECT 1\n FROM webhooks\n WHERE webhooks.id = json_extract(metadata, '$.__relaycast_webhook_id')\n AND webhooks.token_hash IS NOT NULL\n )\n \n \n OR json_extract(metadata, '$.__relaycast_webhook_id') GLOB 'relayfile:*'\n )",
|
|
468
|
+
"INSERT INTO message_sessions (\n workspace_id,\n session_ref,\n first_message_at,\n last_message_at,\n start_is_known\n)\nSELECT\n workspace_id,\n session_ref,\n MIN(created_at),\n MAX(created_at),\n 0\nFROM messages\nWHERE session_ref IS NOT NULL\nGROUP BY workspace_id, session_ref"
|
|
469
|
+
]
|
|
470
|
+
],
|
|
471
|
+
[
|
|
472
|
+
"0039_workspace_usage_attribution.sql",
|
|
473
|
+
[
|
|
474
|
+
"ALTER TABLE workspaces ADD COLUMN provenance TEXT",
|
|
475
|
+
"ALTER TABLE workspaces ADD COLUMN usage_classification TEXT NOT NULL DEFAULT 'unknown'\n CHECK (usage_classification IN ('internal', 'external', 'unknown'))",
|
|
476
|
+
"ALTER TABLE workspaces ADD COLUMN classification_source TEXT NOT NULL DEFAULT 'unclassified'\n CONSTRAINT workspaces_usage_classification_source_check CHECK (\n classification_source IN ('creator', 'operator', 'unclassified')\n AND (\n (usage_classification = 'unknown' AND classification_source = 'unclassified')\n OR (\n usage_classification IN ('internal', 'external')\n AND classification_source IN ('creator', 'operator')\n )\n )\n )",
|
|
477
|
+
"ALTER TABLE workspaces ADD COLUMN classification_reason TEXT",
|
|
478
|
+
"ALTER TABLE workspaces ADD COLUMN classified_at INTEGER",
|
|
479
|
+
"CREATE INDEX IF NOT EXISTS idx_workspaces_usage_classification\n ON workspaces(usage_classification, created_at)"
|
|
480
|
+
]
|
|
481
|
+
],
|
|
482
|
+
[
|
|
483
|
+
"0040_delivery_retry_due_index.sql",
|
|
484
|
+
[
|
|
485
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_retry_due\n ON deliveries(status, next_attempt_at, created_at, id)\n WHERE next_attempt_at IS NOT NULL"
|
|
486
|
+
]
|
|
487
|
+
],
|
|
488
|
+
[
|
|
489
|
+
"0041_agent_identity_recovery.sql",
|
|
490
|
+
[
|
|
491
|
+
"CREATE TABLE agent_recovery_credentials (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n proof_kind TEXT NOT NULL,\n verifier_hash TEXT NOT NULL,\n work_unit_id TEXT,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n updated_at INTEGER NOT NULL DEFAULT (unixepoch()),\n FOREIGN KEY (workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE,\n FOREIGN KEY (workspace_id, agent_id) REFERENCES agents(workspace_id, id) ON DELETE CASCADE\n)",
|
|
492
|
+
"CREATE UNIQUE INDEX agent_recovery_credentials_agent_unique\n ON agent_recovery_credentials(workspace_id, agent_id)",
|
|
493
|
+
"CREATE UNIQUE INDEX agent_recovery_credentials_verifier_unique\n ON agent_recovery_credentials(verifier_hash)",
|
|
494
|
+
"CREATE TABLE agent_identity_audit (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL,\n agent_id TEXT NOT NULL,\n agent_name TEXT NOT NULL,\n action TEXT NOT NULL,\n authority TEXT NOT NULL,\n actor TEXT NOT NULL,\n reason TEXT NOT NULL,\n session_ref TEXT,\n node_id TEXT,\n origin_actor TEXT NOT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n FOREIGN KEY (workspace_id) REFERENCES workspaces(id) ON DELETE CASCADE\n)",
|
|
495
|
+
"CREATE INDEX idx_agent_identity_audit_workspace\n ON agent_identity_audit(workspace_id, created_at)",
|
|
496
|
+
"CREATE INDEX idx_agent_identity_audit_agent\n ON agent_identity_audit(workspace_id, agent_id, created_at)"
|
|
497
|
+
]
|
|
498
|
+
],
|
|
499
|
+
[
|
|
500
|
+
"0041_d1_hot_path_indexes.sql",
|
|
501
|
+
[
|
|
502
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_pending_workspace\n ON action_invocations(workspace_id, created_at)\n WHERE status = 'pending'",
|
|
503
|
+
"CREATE INDEX IF NOT EXISTS idx_dm_conversations_channel\n ON dm_conversations(channel_id)"
|
|
504
|
+
]
|
|
505
|
+
],
|
|
506
|
+
[
|
|
507
|
+
"0042_action_invocation_handler_snapshot.sql",
|
|
508
|
+
[
|
|
509
|
+
"ALTER TABLE action_invocations ADD COLUMN handler_agent_id TEXT",
|
|
510
|
+
"ALTER TABLE action_invocations ADD COLUMN handler_node_id TEXT"
|
|
511
|
+
]
|
|
512
|
+
],
|
|
513
|
+
[
|
|
514
|
+
"0042_d1_read_path_indexes.sql",
|
|
515
|
+
[
|
|
516
|
+
"CREATE INDEX IF NOT EXISTS idx_agents_active_last_seen\n ON agents(last_seen)\n WHERE status IN ('active', 'online')",
|
|
517
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_agent_active_created\n ON deliveries(workspace_id, agent_id, created_at, id)\n WHERE status IN ('queued', 'delivered')"
|
|
518
|
+
]
|
|
519
|
+
],
|
|
520
|
+
[
|
|
521
|
+
"0043_node_machine_id_index.sql",
|
|
522
|
+
[
|
|
523
|
+
"CREATE INDEX IF NOT EXISTS idx_nodes_workspace_machine\n ON nodes(workspace_id, machine_id)"
|
|
524
|
+
]
|
|
525
|
+
],
|
|
526
|
+
[
|
|
527
|
+
"0044_node_proven_live_at.sql",
|
|
528
|
+
[
|
|
529
|
+
"ALTER TABLE nodes ADD COLUMN proven_live_at INTEGER DEFAULT NULL",
|
|
530
|
+
"CREATE INDEX IF NOT EXISTS idx_nodes_workspace_machine_proven\n ON nodes(workspace_id, machine_id, proven_live_at)"
|
|
531
|
+
]
|
|
532
|
+
],
|
|
533
|
+
[
|
|
534
|
+
"0045_workspace_create_idempotency.sql",
|
|
535
|
+
[
|
|
536
|
+
"CREATE TABLE workspace_create_idempotency (\n owner_scope_hash TEXT NOT NULL,\n idempotency_key_hash TEXT NOT NULL,\n request_digest TEXT NOT NULL,\n workspace_id TEXT NOT NULL,\n status TEXT NOT NULL DEFAULT 'active',\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n terminalized_at INTEGER,\n PRIMARY KEY (owner_scope_hash, idempotency_key_hash)\n)",
|
|
537
|
+
"CREATE UNIQUE INDEX workspace_create_idempotency_workspace_unique\n ON workspace_create_idempotency(workspace_id)"
|
|
538
|
+
]
|
|
539
|
+
],
|
|
540
|
+
[
|
|
541
|
+
"0046_action_invocation_origin.sql",
|
|
542
|
+
[
|
|
543
|
+
"ALTER TABLE action_invocations\n ADD COLUMN invocation_origin TEXT NOT NULL DEFAULT 'legacy_unknown'\n CHECK (invocation_origin IN ('legacy_unknown', 'registered_action', 'builtin'))",
|
|
544
|
+
"UPDATE action_invocations\nSET invocation_origin = 'registered_action'\nWHERE action_id IS NOT NULL",
|
|
545
|
+
"UPDATE nodes\nSET reserved_agents = MAX(\n 0,\n reserved_agents - (\n SELECT COUNT(*)\n FROM action_invocations\n WHERE action_invocations.action_id IS NULL\n AND action_invocations.status IN ('pending', 'dispatched', 'invoked')\n AND action_invocations.spawn_reserved_at IS NOT NULL\n AND action_invocations.dispatched_node_id = nodes.id\n )\n)\nWHERE EXISTS (\n SELECT 1\n FROM action_invocations\n WHERE action_invocations.action_id IS NULL\n AND action_invocations.status IN ('pending', 'dispatched', 'invoked')\n AND action_invocations.spawn_reserved_at IS NOT NULL\n AND action_invocations.dispatched_node_id = nodes.id\n)",
|
|
546
|
+
"UPDATE action_invocations\nSET status = 'failed',\n error = 'invocation_origin_unavailable',\n completed_at = unixepoch(),\n spawn_reserved_at = NULL\nWHERE action_id IS NULL\n AND status IN ('pending', 'dispatched', 'invoked')"
|
|
547
|
+
]
|
|
548
|
+
],
|
|
549
|
+
[
|
|
550
|
+
"0047_action_invocation_provider_acceptance.sql",
|
|
551
|
+
[
|
|
552
|
+
"ALTER TABLE action_invocations\n ADD COLUMN provider_accepted_attempt INTEGER DEFAULT NULL",
|
|
553
|
+
"UPDATE action_invocations\nSET provider_accepted_attempt = dispatch_attempts\nWHERE invocation_origin = 'registered_action'\n AND action_id IS NOT NULL\n AND status IN ('dispatched', 'invoked')\n AND dispatch_attempts > 0"
|
|
554
|
+
]
|
|
555
|
+
],
|
|
556
|
+
[
|
|
557
|
+
"0048_bounded_maintenance.sql",
|
|
558
|
+
[
|
|
559
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_agent_active_seq\n ON deliveries(workspace_id, agent_id, seq)\n WHERE status IN ('queued', 'delivered')",
|
|
560
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_agent_active_expiry\n ON deliveries(workspace_id, agent_id, expires_at)\n WHERE status IN ('queued', 'delivered')",
|
|
561
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_initial_due\n ON deliveries(status, created_at, id) WHERE next_attempt_at IS NULL",
|
|
562
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_settled_retention\n ON deliveries(created_at, id)\n WHERE status IN ('acked', 'failed', 'dead_lettered')",
|
|
563
|
+
"CREATE INDEX IF NOT EXISTS idx_workspace_events_retention\n ON workspace_events(created_at, workspace_id, seq)",
|
|
564
|
+
"CREATE INDEX IF NOT EXISTS idx_messages_retention ON messages(length(id), id)",
|
|
565
|
+
"CREATE INDEX IF NOT EXISTS idx_message_logs_retention ON message_logs(length(id), id)",
|
|
566
|
+
"CREATE TABLE IF NOT EXISTS maintenance_cursors (\n id TEXT PRIMARY KEY NOT NULL,\n cursor TEXT NOT NULL\n)"
|
|
567
|
+
]
|
|
568
|
+
],
|
|
569
|
+
[
|
|
570
|
+
"0049_redrive_review_hardening.sql",
|
|
571
|
+
[
|
|
572
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS idx_deliveries_id_lookup ON deliveries(id)",
|
|
573
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS idx_read_receipts_retention ON read_receipts(message_id, agent_id)",
|
|
574
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_node_initial ON deliveries(created_at, id)\n WHERE status = 'queued' AND route_node_kind IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND next_attempt_at IS NULL",
|
|
575
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_node_initial_workspace ON deliveries(workspace_id, created_at, id)\n WHERE status = 'queued' AND route_node_kind IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND next_attempt_at IS NULL",
|
|
576
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_node_retry ON deliveries(next_attempt_at, created_at, id)\n WHERE status = 'queued' AND route_node_kind IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND next_attempt_at IS NOT NULL",
|
|
577
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_node_retry_workspace ON deliveries(workspace_id, next_attempt_at, created_at, id)\n WHERE status = 'queued' AND route_node_kind IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND next_attempt_at IS NOT NULL"
|
|
578
|
+
]
|
|
579
|
+
],
|
|
580
|
+
[
|
|
581
|
+
"0050_compact_maintenance_indexes.sql",
|
|
582
|
+
[
|
|
583
|
+
"DROP INDEX IF EXISTS idx_deliveries_message",
|
|
584
|
+
"DROP INDEX IF EXISTS idx_read_receipts_message",
|
|
585
|
+
"DROP INDEX IF EXISTS idx_deliveries_route_node",
|
|
586
|
+
"DROP INDEX IF EXISTS idx_deliveries_next_attempt",
|
|
587
|
+
"DROP INDEX IF EXISTS idx_deliveries_http_push_due",
|
|
588
|
+
"DROP INDEX IF EXISTS idx_deliveries_initial_due",
|
|
589
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_agent_active_seq\n ON deliveries(workspace_id, agent_id, seq)\n WHERE status IN ('queued', 'delivered')",
|
|
590
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_agent_active_expiry\n ON deliveries(workspace_id, agent_id, expires_at)\n WHERE status IN ('queued', 'delivered')",
|
|
591
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_settled_retention\n ON deliveries(created_at, id)\n WHERE status IN ('acked', 'failed', 'dead_lettered')",
|
|
592
|
+
"CREATE INDEX IF NOT EXISTS idx_workspace_events_retention\n ON workspace_events(created_at, workspace_id, seq)",
|
|
593
|
+
"CREATE INDEX IF NOT EXISTS idx_messages_retention ON messages(length(id), id)",
|
|
594
|
+
"CREATE INDEX IF NOT EXISTS idx_message_logs_retention ON message_logs(length(id), id)",
|
|
595
|
+
"CREATE TABLE IF NOT EXISTS maintenance_cursors (\n id TEXT PRIMARY KEY NOT NULL,\n cursor TEXT NOT NULL\n)",
|
|
596
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS idx_deliveries_id_lookup ON deliveries(id)",
|
|
597
|
+
"CREATE UNIQUE INDEX IF NOT EXISTS idx_read_receipts_retention ON read_receipts(message_id, agent_id)",
|
|
598
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_node_initial ON deliveries(created_at, id)\n WHERE status = 'queued' AND route_node_kind IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND next_attempt_at IS NULL",
|
|
599
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_node_initial_workspace ON deliveries(workspace_id, created_at, id)\n WHERE status = 'queued' AND route_node_kind IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND next_attempt_at IS NULL",
|
|
600
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_node_retry ON deliveries(next_attempt_at, created_at, id)\n WHERE status = 'queued' AND route_node_kind IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND next_attempt_at IS NOT NULL",
|
|
601
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_node_retry_workspace ON deliveries(workspace_id, next_attempt_at, created_at, id)\n WHERE status = 'queued' AND route_node_kind IN ('http_push', 'ws', 'fleet_ws', 'direct_ws') AND next_attempt_at IS NOT NULL"
|
|
602
|
+
]
|
|
603
|
+
],
|
|
604
|
+
[
|
|
605
|
+
"0051_node_foreign_key_indexes.sql",
|
|
606
|
+
[
|
|
607
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_location_node_fk\n ON deliveries(location_node_id) WHERE location_node_id IS NOT NULL",
|
|
608
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_route_node_fk\n ON deliveries(route_node_id) WHERE route_node_id IS NOT NULL",
|
|
609
|
+
"CREATE INDEX IF NOT EXISTS idx_agents_location_node_fk\n ON agents(location_node_id) WHERE location_node_id IS NOT NULL",
|
|
610
|
+
"CREATE INDEX IF NOT EXISTS idx_agents_origin_node_fk\n ON agents(origin_node_id) WHERE origin_node_id IS NOT NULL",
|
|
611
|
+
"CREATE INDEX IF NOT EXISTS idx_agent_node_bindings_node_fk\n ON agent_node_bindings(node_id)",
|
|
612
|
+
"CREATE INDEX IF NOT EXISTS idx_node_providers_node_fk\n ON node_providers(node_id)"
|
|
613
|
+
]
|
|
614
|
+
],
|
|
615
|
+
[
|
|
616
|
+
"0052_agent_roster_index.sql",
|
|
617
|
+
[
|
|
618
|
+
"CREATE INDEX IF NOT EXISTS idx_agents_roster\n ON agents(workspace_id, status, last_seen) WHERE status <> 'released'"
|
|
619
|
+
]
|
|
620
|
+
],
|
|
621
|
+
[
|
|
622
|
+
"0053_agent_retention_indexes.sql",
|
|
623
|
+
[
|
|
624
|
+
"CREATE INDEX IF NOT EXISTS idx_messages_agent ON messages(agent_id)",
|
|
625
|
+
"CREATE INDEX IF NOT EXISTS idx_channels_creator ON channels(created_by)",
|
|
626
|
+
"CREATE INDEX IF NOT EXISTS idx_webhooks_creator ON webhooks(created_by)",
|
|
627
|
+
"CREATE INDEX IF NOT EXISTS idx_reactions_agent ON reactions(agent_id)",
|
|
628
|
+
"CREATE INDEX IF NOT EXISTS idx_directory_ratings_rater ON directory_ratings(rater_agent_id)",
|
|
629
|
+
"CREATE INDEX IF NOT EXISTS idx_routing_failures_agent ON routing_failures(agent_id)"
|
|
630
|
+
]
|
|
631
|
+
],
|
|
632
|
+
[
|
|
633
|
+
"0054_node_status_heartbeat_index.sql",
|
|
634
|
+
[
|
|
635
|
+
"CREATE INDEX IF NOT EXISTS idx_nodes_status_heartbeat\n ON nodes(workspace_id, status, last_heartbeat_at)"
|
|
636
|
+
]
|
|
637
|
+
],
|
|
638
|
+
[
|
|
639
|
+
"0055_session_event_idempotency.sql",
|
|
640
|
+
[
|
|
641
|
+
"ALTER TABLE session_events ADD COLUMN idempotency_key_hash TEXT",
|
|
642
|
+
"ALTER TABLE session_events ADD COLUMN request_digest TEXT",
|
|
643
|
+
"CREATE UNIQUE INDEX session_events_agent_idempotency_unique\n ON session_events(workspace_id, agent_id, idempotency_key_hash)"
|
|
644
|
+
]
|
|
645
|
+
],
|
|
646
|
+
[
|
|
647
|
+
"0056_session_event_status_completion.sql",
|
|
648
|
+
[
|
|
649
|
+
"ALTER TABLE agents ADD COLUMN status_updated_at INTEGER",
|
|
650
|
+
"ALTER TABLE session_events ADD COLUMN status_applied_at INTEGER",
|
|
651
|
+
"ALTER TABLE session_events ADD COLUMN status_legacy_pending INTEGER NOT NULL DEFAULT 0",
|
|
652
|
+
"UPDATE agents\nSET status_updated_at = last_seen\nWHERE status_updated_at IS NULL",
|
|
653
|
+
"CREATE TRIGGER agents_status_reconciliation_timestamp\nAFTER UPDATE OF status, last_seen ON agents\nFOR EACH ROW\nBEGIN\n UPDATE agents\n SET status_updated_at = unixepoch()\n WHERE id = NEW.id;\nEND",
|
|
654
|
+
"UPDATE session_events\nSET status_legacy_pending = 1\nWHERE idempotency_key_hash IS NOT NULL\n AND type LIKE 'status.%'"
|
|
655
|
+
]
|
|
656
|
+
],
|
|
657
|
+
[
|
|
658
|
+
"0057_a2a_egress.sql",
|
|
659
|
+
[
|
|
660
|
+
"CREATE TABLE IF NOT EXISTS a2a_egress (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n message_id TEXT NOT NULL,\n target_id TEXT NOT NULL,\n external_url TEXT NOT NULL,\n fingerprint TEXT NOT NULL,\n payload TEXT,\n status TEXT NOT NULL DEFAULT 'pending',\n claim_token TEXT,\n lease_until INTEGER,\n attempts INTEGER NOT NULL DEFAULT 0,\n last_error TEXT,\n error_status INTEGER,\n error_code TEXT,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
661
|
+
"CREATE INDEX IF NOT EXISTS idx_a2a_egress_due ON a2a_egress(status, lease_until)",
|
|
662
|
+
"CREATE INDEX IF NOT EXISTS idx_a2a_egress_retention ON a2a_egress(created_at, id)"
|
|
663
|
+
]
|
|
664
|
+
],
|
|
665
|
+
[
|
|
666
|
+
"0058_a2a_egress_context.sql",
|
|
667
|
+
[
|
|
668
|
+
"CREATE TABLE IF NOT EXISTS a2a_egress_context (\n id TEXT PRIMARY KEY NOT NULL REFERENCES a2a_egress(id) ON DELETE CASCADE,\n message_id TEXT NOT NULL REFERENCES messages(id) ON DELETE CASCADE,\n response TEXT NOT NULL\n)",
|
|
669
|
+
"CREATE INDEX IF NOT EXISTS idx_a2a_egress_context_message ON a2a_egress_context(message_id)"
|
|
670
|
+
]
|
|
671
|
+
],
|
|
672
|
+
[
|
|
673
|
+
"0059_a2a_inbound_admission.sql",
|
|
674
|
+
[
|
|
675
|
+
"CREATE INDEX IF NOT EXISTS idx_a2a_egress_workspace ON a2a_egress(workspace_id)",
|
|
676
|
+
"CREATE TABLE IF NOT EXISTS a2a_inbound (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n message_id TEXT REFERENCES messages(id) ON DELETE SET NULL,\n fingerprint TEXT NOT NULL,\n response TEXT,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
677
|
+
"CREATE INDEX IF NOT EXISTS idx_a2a_inbound_workspace ON a2a_inbound(workspace_id)",
|
|
678
|
+
"CREATE INDEX IF NOT EXISTS idx_a2a_inbound_message ON a2a_inbound(message_id)",
|
|
679
|
+
"CREATE INDEX IF NOT EXISTS idx_a2a_inbound_retention ON a2a_inbound(created_at, id)",
|
|
680
|
+
"CREATE TRIGGER IF NOT EXISTS a2a_inbound_source_prune\nBEFORE DELETE ON messages\nBEGIN\n UPDATE a2a_inbound SET response = NULL WHERE message_id = OLD.id;\nEND"
|
|
681
|
+
]
|
|
682
|
+
],
|
|
683
|
+
[
|
|
684
|
+
"0060_durable_task_invocations.sql",
|
|
685
|
+
[
|
|
686
|
+
"ALTER TABLE actions ADD COLUMN execution_mode TEXT NOT NULL DEFAULT 'short'",
|
|
687
|
+
"ALTER TABLE action_invocations ADD COLUMN task_state TEXT",
|
|
688
|
+
"CREATE INDEX idx_action_invocations_task_deadline\n ON action_invocations(json_extract(task_state, '$.deadline'))\n WHERE task_state IS NOT NULL AND status IN ('pending', 'dispatched', 'running')"
|
|
689
|
+
]
|
|
690
|
+
],
|
|
691
|
+
[
|
|
692
|
+
"0061_messages_workspace_length_id_index.sql",
|
|
693
|
+
[
|
|
694
|
+
"CREATE INDEX IF NOT EXISTS idx_messages_workspace_length_id\n ON messages(workspace_id, length(id), id)"
|
|
695
|
+
]
|
|
696
|
+
],
|
|
697
|
+
[
|
|
698
|
+
"0062_direct_dm_idempotency.sql",
|
|
699
|
+
[
|
|
700
|
+
"CREATE TABLE direct_dm_idempotency (\n id TEXT PRIMARY KEY NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n message_id TEXT NOT NULL,\n fingerprint TEXT NOT NULL,\n response TEXT NOT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch())\n)",
|
|
701
|
+
"CREATE INDEX idx_direct_dm_idempotency_workspace_created\n ON direct_dm_idempotency(workspace_id, created_at)",
|
|
702
|
+
"CREATE INDEX idx_direct_dm_idempotency_retention\n ON direct_dm_idempotency(created_at, id)"
|
|
703
|
+
]
|
|
704
|
+
],
|
|
705
|
+
[
|
|
706
|
+
"0063_node_rotation_recovery.sql",
|
|
707
|
+
[
|
|
708
|
+
"ALTER TABLE nodes ADD COLUMN previous_token_hash TEXT DEFAULT NULL",
|
|
709
|
+
"ALTER TABLE nodes ADD COLUMN previous_token_expires_at INTEGER DEFAULT NULL",
|
|
710
|
+
"ALTER TABLE nodes ADD COLUMN rotation_idempotency_key_hash TEXT DEFAULT NULL",
|
|
711
|
+
"ALTER TABLE nodes ADD COLUMN rotation_request_digest TEXT DEFAULT NULL",
|
|
712
|
+
"CREATE INDEX IF NOT EXISTS idx_nodes_workspace_previous_token\n ON nodes(workspace_id, previous_token_hash)"
|
|
713
|
+
]
|
|
714
|
+
],
|
|
715
|
+
[
|
|
716
|
+
"0064_action_invocations_status_dispatched_index.sql",
|
|
717
|
+
[
|
|
718
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_status_dispatched\n ON action_invocations(status, dispatched_at)"
|
|
719
|
+
]
|
|
720
|
+
],
|
|
721
|
+
[
|
|
722
|
+
"0065_action_invocations_task_deadline_any_status.sql",
|
|
723
|
+
[
|
|
724
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_task_deadline_any_status\n ON action_invocations(json_extract(task_state, '$.deadline'))\n WHERE task_state IS NOT NULL"
|
|
725
|
+
]
|
|
726
|
+
],
|
|
727
|
+
[
|
|
728
|
+
"0066_action_invocations_status_sweep_ranges.sql",
|
|
729
|
+
[
|
|
730
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_status_retry_after\n ON action_invocations(status, retry_after_at)",
|
|
731
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_status_task_deadline\n ON action_invocations(status, json_extract(task_state, '$.deadline'))\n WHERE task_state IS NOT NULL",
|
|
732
|
+
"DROP INDEX IF EXISTS idx_action_invocations_task_deadline_any_status"
|
|
733
|
+
]
|
|
734
|
+
],
|
|
735
|
+
[
|
|
736
|
+
"0067_webhook_delivery_reliability.sql",
|
|
737
|
+
[
|
|
738
|
+
"ALTER TABLE event_subscriptions\n ADD COLUMN signature_scheme TEXT NOT NULL DEFAULT 'legacy'",
|
|
739
|
+
"ALTER TABLE pending_events\n ADD COLUMN webhook_initialized INTEGER NOT NULL DEFAULT 0",
|
|
740
|
+
"CREATE TABLE webhook_deliveries (\n id TEXT PRIMARY KEY NOT NULL,\n event_id TEXT NOT NULL REFERENCES pending_events(id) ON DELETE CASCADE,\n subscription_id TEXT NOT NULL REFERENCES event_subscriptions(id) ON DELETE CASCADE,\n status TEXT NOT NULL DEFAULT 'pending',\n attempts INTEGER NOT NULL DEFAULT 0,\n next_attempt_at INTEGER NOT NULL DEFAULT (unixepoch()),\n last_error TEXT,\n last_status INTEGER,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n completed_at INTEGER\n)",
|
|
741
|
+
"CREATE UNIQUE INDEX webhook_deliveries_event_subscription_unique\n ON webhook_deliveries(event_id, subscription_id)",
|
|
742
|
+
"CREATE INDEX idx_webhook_deliveries_due\n ON webhook_deliveries(status, next_attempt_at)",
|
|
743
|
+
"CREATE INDEX idx_webhook_deliveries_subscription\n ON webhook_deliveries(subscription_id, created_at)",
|
|
744
|
+
"UPDATE pending_events\n SET max_attempts = 32\n WHERE status = 'pending' AND max_attempts < 32"
|
|
745
|
+
]
|
|
746
|
+
],
|
|
747
|
+
[
|
|
748
|
+
"0068_spawn_canceled_index.sql",
|
|
749
|
+
[
|
|
750
|
+
"CREATE INDEX IF NOT EXISTS idx_action_invocations_spawn_canceled\n ON action_invocations(workspace_id, dispatched_node_id)"
|
|
751
|
+
]
|
|
752
|
+
],
|
|
753
|
+
[
|
|
754
|
+
"0069_nodes_online_liveness_index.sql",
|
|
755
|
+
[
|
|
756
|
+
"CREATE INDEX IF NOT EXISTS idx_nodes_online_liveness\n ON nodes(last_heartbeat_at, workspace_id, id)\n WHERE status = 'online'"
|
|
757
|
+
]
|
|
758
|
+
],
|
|
759
|
+
[
|
|
760
|
+
"0070_agent_liveness_status.sql",
|
|
761
|
+
[
|
|
762
|
+
"ALTER TABLE agents ADD COLUMN status_before_liveness_loss TEXT",
|
|
763
|
+
"CREATE TRIGGER agents_clear_liveness_recovery\nAFTER UPDATE OF status ON agents\nFOR EACH ROW\nWHEN NEW.status_before_liveness_loss IS NOT NULL\n AND NEW.status_before_liveness_loss IS OLD.status_before_liveness_loss\nBEGIN\n UPDATE agents SET status_before_liveness_loss = NULL WHERE id = NEW.id;\nEND"
|
|
764
|
+
]
|
|
765
|
+
],
|
|
766
|
+
[
|
|
767
|
+
"0071_node_liveness_revision.sql",
|
|
768
|
+
[
|
|
769
|
+
"ALTER TABLE nodes ADD COLUMN liveness_revision INTEGER NOT NULL DEFAULT 0",
|
|
770
|
+
"ALTER TABLE node_providers ADD COLUMN liveness_revision INTEGER NOT NULL DEFAULT 0",
|
|
771
|
+
"ALTER TABLE agents ADD COLUMN node_liveness_revision INTEGER NOT NULL DEFAULT 0",
|
|
772
|
+
"ALTER TABLE action_invocations ADD COLUMN node_liveness_revision INTEGER NOT NULL DEFAULT 0",
|
|
773
|
+
"CREATE INDEX idx_node_providers_liveness_revision\n ON node_providers(workspace_id, node_id, liveness_revision)",
|
|
774
|
+
"CREATE INDEX idx_agents_location_node_liveness_revision\n ON agents(workspace_id, location_node_id, node_liveness_revision)\n WHERE location_type = 'via_node'\n AND location_node_id IS NOT NULL\n AND status NOT IN ('offline', 'released')",
|
|
775
|
+
"CREATE INDEX idx_action_invocations_dispatched_node_liveness_revision\n ON action_invocations(workspace_id, dispatched_node_id, node_liveness_revision)\n WHERE dispatched_node_id IS NOT NULL\n AND status IN ('pending', 'dispatched', 'invoked')",
|
|
776
|
+
"CREATE TRIGGER nodes_advance_liveness_revision\nAFTER UPDATE OF status, last_heartbeat_at ON nodes\nFOR EACH ROW\nWHEN NEW.liveness_revision = OLD.liveness_revision\nBEGIN\n UPDATE nodes\n SET liveness_revision = OLD.liveness_revision + 1\n WHERE id = NEW.id;\nEND",
|
|
777
|
+
"CREATE TRIGGER node_providers_stamp_liveness_revision_insert\nAFTER INSERT ON node_providers\nFOR EACH ROW\nBEGIN\n UPDATE node_providers\n SET liveness_revision = COALESCE((\n SELECT liveness_revision + 1\n FROM nodes\n WHERE workspace_id = NEW.workspace_id AND id = NEW.node_id\n ), 1)\n WHERE id = NEW.id;\nEND",
|
|
778
|
+
"CREATE TRIGGER node_providers_stamp_liveness_revision_update\nAFTER UPDATE OF status, last_heartbeat_at, instance_id ON node_providers\nFOR EACH ROW\nWHEN NEW.liveness_revision = OLD.liveness_revision\nBEGIN\n UPDATE node_providers\n SET liveness_revision = COALESCE((\n SELECT liveness_revision + 1\n FROM nodes\n WHERE workspace_id = NEW.workspace_id AND id = NEW.node_id\n ), OLD.liveness_revision + 1)\n WHERE id = NEW.id;\nEND",
|
|
779
|
+
"CREATE TRIGGER agents_stamp_node_liveness_revision_insert\nAFTER INSERT ON agents\nFOR EACH ROW\nWHEN NEW.location_type = 'via_node' AND NEW.location_node_id IS NOT NULL\nBEGIN\n UPDATE agents\n SET node_liveness_revision = COALESCE((\n SELECT liveness_revision + 1\n FROM nodes\n WHERE workspace_id = NEW.workspace_id AND id = NEW.location_node_id\n ), 1)\n WHERE id = NEW.id;\nEND",
|
|
780
|
+
"CREATE TRIGGER agents_stamp_node_liveness_revision_update\nAFTER UPDATE OF status, last_seen, location_type, location_node_id, provider_name ON agents\nFOR EACH ROW\nWHEN NEW.location_type = 'via_node'\n AND NEW.location_node_id IS NOT NULL\n AND NEW.node_liveness_revision = OLD.node_liveness_revision\nBEGIN\n UPDATE agents\n SET node_liveness_revision = COALESCE((\n SELECT liveness_revision + 1\n FROM nodes\n WHERE workspace_id = NEW.workspace_id AND id = NEW.location_node_id\n ), OLD.node_liveness_revision + 1)\n WHERE id = NEW.id;\nEND",
|
|
781
|
+
"CREATE TRIGGER action_invocations_stamp_node_liveness_revision_insert\nAFTER INSERT ON action_invocations\nFOR EACH ROW\nWHEN NEW.dispatched_node_id IS NOT NULL\nBEGIN\n UPDATE action_invocations\n SET node_liveness_revision = COALESCE((\n SELECT liveness_revision + 1\n FROM nodes\n WHERE workspace_id = NEW.workspace_id AND id = NEW.dispatched_node_id\n ), 1)\n WHERE id = NEW.id;\nEND",
|
|
782
|
+
"CREATE TRIGGER action_invocations_stamp_node_liveness_revision_update\nAFTER UPDATE OF status, dispatched_node_id, dispatched_at, dispatch_attempts ON action_invocations\nFOR EACH ROW\nWHEN NEW.dispatched_node_id IS NOT NULL\n AND NEW.node_liveness_revision = OLD.node_liveness_revision\nBEGIN\n UPDATE action_invocations\n SET node_liveness_revision = COALESCE((\n SELECT liveness_revision + 1\n FROM nodes\n WHERE workspace_id = NEW.workspace_id AND id = NEW.dispatched_node_id\n ), OLD.node_liveness_revision + 1)\n WHERE id = NEW.id;\nEND"
|
|
783
|
+
]
|
|
784
|
+
],
|
|
785
|
+
[
|
|
786
|
+
"0073_workspace_key_rotation.sql",
|
|
787
|
+
[
|
|
788
|
+
"ALTER TABLE workspaces ADD COLUMN previous_api_key_hash TEXT",
|
|
789
|
+
"ALTER TABLE workspaces ADD COLUMN previous_api_key_expires_at INTEGER",
|
|
790
|
+
"ALTER TABLE workspaces ADD COLUMN api_key_generation INTEGER NOT NULL DEFAULT 0",
|
|
791
|
+
"CREATE INDEX idx_workspaces_previous_api_key\n ON workspaces(previous_api_key_hash)"
|
|
792
|
+
]
|
|
793
|
+
],
|
|
794
|
+
[
|
|
795
|
+
"0074_delivery_active_location_node_index.sql",
|
|
796
|
+
[
|
|
797
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_active_location_node\n ON deliveries(location_node_id)\n WHERE status IN ('queued', 'delivered') AND location_node_id IS NOT NULL"
|
|
798
|
+
]
|
|
799
|
+
],
|
|
800
|
+
[
|
|
801
|
+
"0075_message_mention_fts.sql",
|
|
802
|
+
[
|
|
803
|
+
"CREATE VIRTUAL TABLE IF NOT EXISTS messages_mention_fts USING fts5(\n workspace_id,\n body,\n content=messages,\n content_rowid=rowid,\n tokenize='unicode61'\n)",
|
|
804
|
+
"CREATE TRIGGER IF NOT EXISTS messages_mention_fts_insert AFTER INSERT ON messages BEGIN\n INSERT INTO messages_mention_fts(rowid, workspace_id, body)\n SELECT NEW.rowid, NEW.workspace_id, NEW.body\n WHERE NOT EXISTS (\n SELECT 1 FROM messages_mention_fts_docsize WHERE id = NEW.rowid\n );\nEND",
|
|
805
|
+
"CREATE TRIGGER IF NOT EXISTS messages_mention_fts_update AFTER UPDATE OF body, workspace_id ON messages BEGIN\n INSERT INTO messages_mention_fts(messages_mention_fts, rowid, workspace_id, body)\n SELECT 'delete', OLD.rowid, OLD.workspace_id, OLD.body\n WHERE EXISTS (\n SELECT 1 FROM messages_mention_fts_docsize WHERE id = OLD.rowid\n );\n INSERT INTO messages_mention_fts(rowid, workspace_id, body)\n SELECT NEW.rowid, NEW.workspace_id, NEW.body\n WHERE NOT EXISTS (\n SELECT 1 FROM messages_mention_fts_docsize WHERE id = NEW.rowid\n );\nEND",
|
|
806
|
+
"CREATE TRIGGER IF NOT EXISTS messages_mention_fts_delete AFTER DELETE ON messages BEGIN\n INSERT INTO messages_mention_fts(messages_mention_fts, rowid, workspace_id, body)\n SELECT 'delete', OLD.rowid, OLD.workspace_id, OLD.body\n WHERE EXISTS (\n SELECT 1 FROM messages_mention_fts_docsize WHERE id = OLD.rowid\n );\nEND",
|
|
807
|
+
"INSERT INTO maintenance_cursors(id, cursor)\nSELECT 'mention-fts-backfill',\n CASE\n WHEN EXISTS (SELECT 1 FROM messages)\n THEN '0/' || (SELECT MAX(rowid) FROM messages)\n ELSE 'complete'\n END\nWHERE NOT EXISTS (\n SELECT 1 FROM maintenance_cursors WHERE id = 'mention-fts-backfill'\n)"
|
|
808
|
+
]
|
|
809
|
+
],
|
|
810
|
+
[
|
|
811
|
+
"0076_deliveries_agent_status_created_index.sql",
|
|
812
|
+
[
|
|
813
|
+
"CREATE INDEX IF NOT EXISTS idx_deliveries_agent_status_created\n ON deliveries(workspace_id, agent_id, status, created_at, id)"
|
|
814
|
+
]
|
|
815
|
+
],
|
|
816
|
+
[
|
|
817
|
+
"0077_drop_workspace_plan.sql",
|
|
818
|
+
[
|
|
819
|
+
"ALTER TABLE `workspaces` DROP COLUMN `plan`"
|
|
820
|
+
]
|
|
821
|
+
],
|
|
822
|
+
[
|
|
823
|
+
"0078_dm_participant_read_cursor.sql",
|
|
824
|
+
[
|
|
825
|
+
"ALTER TABLE dm_participants ADD COLUMN last_read_id TEXT",
|
|
826
|
+
"UPDATE dm_participants SET last_read_id = (\n SELECT CAST(MAX(CAST(m.id AS INTEGER)) AS TEXT)\n FROM dm_conversations dc\n JOIN messages m ON m.channel_id = dc.channel_id\n JOIN read_receipts rr ON rr.message_id = m.id AND rr.agent_id = dm_participants.agent_id\n WHERE dc.id = dm_participants.conversation_id\n)"
|
|
827
|
+
]
|
|
828
|
+
],
|
|
829
|
+
[
|
|
830
|
+
"0079_credential_upgrades.sql",
|
|
831
|
+
[
|
|
832
|
+
"CREATE TABLE credential_upgrades (\n legacy_hash TEXT PRIMARY KEY NOT NULL,\n kind TEXT NOT NULL,\n principal_id TEXT NOT NULL,\n workspace_id TEXT NOT NULL REFERENCES workspaces(id) ON DELETE CASCADE,\n ar_hash TEXT NOT NULL,\n sealed_credential TEXT NOT NULL,\n created_at INTEGER NOT NULL DEFAULT (unixepoch()),\n expires_at INTEGER NOT NULL\n)",
|
|
833
|
+
"CREATE INDEX idx_credential_upgrades_workspace ON credential_upgrades(workspace_id)"
|
|
834
|
+
]
|
|
835
|
+
]
|
|
836
|
+
];
|
|
837
|
+
/** `src/db/migrations/supersessions.json`. */
|
|
838
|
+
export const ACTOR_MIGRATION_SUPERSESSIONS = {
|
|
839
|
+
"0048_bounded_maintenance.sql": "0050_compact_maintenance_indexes.sql",
|
|
840
|
+
"0049_redrive_review_hardening.sql": "0050_compact_maintenance_indexes.sql"
|
|
841
|
+
};
|
|
842
|
+
//# sourceMappingURL=migrations.generated.js.map
|