@rudderhq/db 0.4.6-canary.8 → 0.5.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/client.test.js +629 -0
- package/dist/client.test.js.map +1 -1
- package/dist/embedded-postgres-recovery.d.ts +1 -0
- package/dist/embedded-postgres-recovery.d.ts.map +1 -1
- package/dist/embedded-postgres-recovery.js +33 -0
- package/dist/embedded-postgres-recovery.js.map +1 -1
- package/dist/embedded-postgres-recovery.test.js +19 -1
- package/dist/embedded-postgres-recovery.test.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/migration-runtime.d.ts.map +1 -1
- package/dist/migration-runtime.js +3 -20
- package/dist/migration-runtime.js.map +1 -1
- package/dist/migrations/0101_bizarre_morlun.sql +111 -0
- package/dist/migrations/0102_complex_retro_girl.sql +38 -0
- package/dist/migrations/0103_cute_colonel_america.sql +4 -0
- package/dist/migrations/0104_unusual_mister_fear.sql +173 -0
- package/dist/migrations/0105_chat_queue_actor_reconciliation.sql +54 -0
- package/dist/migrations/0106_damp_amphibian.sql +9 -0
- package/dist/migrations/meta/0101_snapshot.json +18860 -0
- package/dist/migrations/meta/0102_snapshot.json +19090 -0
- package/dist/migrations/meta/0103_snapshot.json +19114 -0
- package/dist/migrations/meta/0104_snapshot.json +20338 -0
- package/dist/migrations/meta/0105_snapshot.json +20338 -0
- package/dist/migrations/meta/0106_snapshot.json +20442 -0
- package/dist/migrations/meta/_journal.json +42 -0
- package/dist/schema/activity_log.d.ts +17 -0
- package/dist/schema/activity_log.d.ts.map +1 -1
- package/dist/schema/activity_log.js +6 -1
- package/dist/schema/activity_log.js.map +1 -1
- package/dist/schema/agent_wakeup_requests.d.ts.map +1 -1
- package/dist/schema/agent_wakeup_requests.js +5 -1
- package/dist/schema/agent_wakeup_requests.js.map +1 -1
- package/dist/schema/chat_control_actions.d.ts +442 -0
- package/dist/schema/chat_control_actions.d.ts.map +1 -0
- package/dist/schema/chat_control_actions.js +35 -0
- package/dist/schema/chat_control_actions.js.map +1 -0
- package/dist/schema/chat_conversations.d.ts +119 -0
- package/dist/schema/chat_conversations.d.ts.map +1 -1
- package/dist/schema/chat_conversations.js +10 -1
- package/dist/schema/chat_conversations.js.map +1 -1
- package/dist/schema/chat_generation_events.d.ts +268 -0
- package/dist/schema/chat_generation_events.d.ts.map +1 -0
- package/dist/schema/chat_generation_events.js +32 -0
- package/dist/schema/chat_generation_events.js.map +1 -0
- package/dist/schema/chat_generation_terminal_outbox.d.ts +370 -0
- package/dist/schema/chat_generation_terminal_outbox.d.ts.map +1 -0
- package/dist/schema/chat_generation_terminal_outbox.js +33 -0
- package/dist/schema/chat_generation_terminal_outbox.js.map +1 -0
- package/dist/schema/chat_generations.d.ts +279 -2
- package/dist/schema/chat_generations.d.ts.map +1 -1
- package/dist/schema/chat_generations.js +23 -2
- package/dist/schema/chat_generations.js.map +1 -1
- package/dist/schema/chat_queued_messages.d.ts +285 -2
- package/dist/schema/chat_queued_messages.d.ts.map +1 -1
- package/dist/schema/chat_queued_messages.js +23 -1
- package/dist/schema/chat_queued_messages.js.map +1 -1
- package/dist/schema/cost_events.d.ts +34 -0
- package/dist/schema/cost_events.d.ts.map +1 -1
- package/dist/schema/cost_events.js +5 -1
- package/dist/schema/cost_events.js.map +1 -1
- package/dist/schema/heartbeat_run_events.d.ts +17 -0
- package/dist/schema/heartbeat_run_events.d.ts.map +1 -1
- package/dist/schema/heartbeat_run_events.js +6 -1
- package/dist/schema/heartbeat_run_events.js.map +1 -1
- package/dist/schema/heartbeat_runs.d.ts +322 -0
- package/dist/schema/heartbeat_runs.d.ts.map +1 -1
- package/dist/schema/heartbeat_runs.js +26 -2
- package/dist/schema/heartbeat_runs.js.map +1 -1
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +3 -0
- package/dist/schema/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
CREATE TABLE "chat_control_actions" (
|
|
2
|
+
"id" uuid PRIMARY KEY NOT NULL,
|
|
3
|
+
"org_id" uuid NOT NULL,
|
|
4
|
+
"expected_generation_id" uuid,
|
|
5
|
+
"expected_attempt_epoch" integer,
|
|
6
|
+
"expected_control_version" integer,
|
|
7
|
+
"applied_control_version" integer,
|
|
8
|
+
"action_kind" text NOT NULL,
|
|
9
|
+
"local_disposition" text DEFAULT 'pending' NOT NULL,
|
|
10
|
+
"provider_disposition" text,
|
|
11
|
+
"control_owner_token" text,
|
|
12
|
+
"provider_client_message_id" text,
|
|
13
|
+
"provider_thread_id" text,
|
|
14
|
+
"provider_turn_id" text,
|
|
15
|
+
"provider_evidence" jsonb,
|
|
16
|
+
"requested_render_seq" integer,
|
|
17
|
+
"requested_body_hash" text,
|
|
18
|
+
"accepted_through_seq" integer,
|
|
19
|
+
"frozen_body_hash" text,
|
|
20
|
+
"last_error" text,
|
|
21
|
+
"requested_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
22
|
+
"provider_sent_at" timestamp with time zone,
|
|
23
|
+
"provider_acknowledged_at" timestamp with time zone,
|
|
24
|
+
"resolved_at" timestamp with time zone,
|
|
25
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
26
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
27
|
+
);
|
|
28
|
+
--> statement-breakpoint
|
|
29
|
+
CREATE TABLE "chat_generation_events" (
|
|
30
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
31
|
+
"org_id" uuid NOT NULL,
|
|
32
|
+
"generation_id" uuid NOT NULL,
|
|
33
|
+
"generation_seq" integer NOT NULL,
|
|
34
|
+
"attempt_epoch" integer NOT NULL,
|
|
35
|
+
"event_kind" text NOT NULL,
|
|
36
|
+
"payload" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
37
|
+
"body_offset" integer,
|
|
38
|
+
"body_length" integer,
|
|
39
|
+
"assistant_message_id" uuid,
|
|
40
|
+
"run_id" uuid,
|
|
41
|
+
"control_action_id" uuid,
|
|
42
|
+
"queue_item_id" uuid,
|
|
43
|
+
"recorded_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
44
|
+
"emitted_at" timestamp with time zone
|
|
45
|
+
);
|
|
46
|
+
--> statement-breakpoint
|
|
47
|
+
CREATE TABLE "chat_generation_terminal_outbox" (
|
|
48
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
49
|
+
"org_id" uuid NOT NULL,
|
|
50
|
+
"generation_id" uuid NOT NULL,
|
|
51
|
+
"source_event_id" uuid NOT NULL,
|
|
52
|
+
"projection_version" integer NOT NULL,
|
|
53
|
+
"projector_version" integer DEFAULT 1 NOT NULL,
|
|
54
|
+
"expected_control_version" integer NOT NULL,
|
|
55
|
+
"status" text DEFAULT 'pending' NOT NULL,
|
|
56
|
+
"payload" jsonb DEFAULT '{}'::jsonb NOT NULL,
|
|
57
|
+
"claim_token" text,
|
|
58
|
+
"claim_epoch" integer DEFAULT 0 NOT NULL,
|
|
59
|
+
"claim_owner" text,
|
|
60
|
+
"lease_expires_at" timestamp with time zone,
|
|
61
|
+
"attempt_count" integer DEFAULT 0 NOT NULL,
|
|
62
|
+
"replay_count" integer DEFAULT 0 NOT NULL,
|
|
63
|
+
"available_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
64
|
+
"last_attempt_at" timestamp with time zone,
|
|
65
|
+
"last_error" text,
|
|
66
|
+
"projected_at" timestamp with time zone,
|
|
67
|
+
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
68
|
+
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
69
|
+
);
|
|
70
|
+
--> statement-breakpoint
|
|
71
|
+
ALTER TABLE "chat_generations" ADD COLUMN "attempt_epoch" integer DEFAULT 1 NOT NULL;--> statement-breakpoint
|
|
72
|
+
ALTER TABLE "chat_generations" ADD COLUMN "control_version" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
73
|
+
ALTER TABLE "chat_generations" ADD COLUMN "control_state" text DEFAULT 'unregistered' NOT NULL;--> statement-breakpoint
|
|
74
|
+
ALTER TABLE "chat_generations" ADD COLUMN "control_runtime_type" text;--> statement-breakpoint
|
|
75
|
+
ALTER TABLE "chat_generations" ADD COLUMN "control_owner_token" text;--> statement-breakpoint
|
|
76
|
+
ALTER TABLE "chat_generations" ADD COLUMN "control_lease_expires_at" timestamp with time zone;--> statement-breakpoint
|
|
77
|
+
ALTER TABLE "chat_generations" ADD COLUMN "provider_thread_id" text;--> statement-breakpoint
|
|
78
|
+
ALTER TABLE "chat_generations" ADD COLUMN "provider_turn_id" text;--> statement-breakpoint
|
|
79
|
+
ALTER TABLE "chat_generations" ADD COLUMN "accepted_through_seq" integer;--> statement-breakpoint
|
|
80
|
+
ALTER TABLE "chat_generations" ADD COLUMN "last_client_checkpoint_seq" integer;--> statement-breakpoint
|
|
81
|
+
ALTER TABLE "chat_generations" ADD COLUMN "last_client_checkpoint_hash" text;--> statement-breakpoint
|
|
82
|
+
ALTER TABLE "chat_generations" ADD COLUMN "frozen_body_hash" text;--> statement-breakpoint
|
|
83
|
+
ALTER TABLE "chat_generations" ADD COLUMN "stop_requested_at" timestamp with time zone;--> statement-breakpoint
|
|
84
|
+
ALTER TABLE "chat_generations" ADD COLUMN "runtime_terminal_at" timestamp with time zone;--> statement-breakpoint
|
|
85
|
+
ALTER TABLE "chat_generations" ADD COLUMN "late_events_dropped" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
86
|
+
ALTER TABLE "chat_generations" ADD COLUMN "late_bytes" bigint DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
87
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "request_actor" jsonb;--> statement-breakpoint
|
|
88
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "delivery_intent" text DEFAULT 'queue' NOT NULL;--> statement-breakpoint
|
|
89
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "delivery_disposition" text;--> statement-breakpoint
|
|
90
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "control_action_id" uuid;--> statement-breakpoint
|
|
91
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "attempt_epoch" integer;--> statement-breakpoint
|
|
92
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "provider_client_message_id" text;--> statement-breakpoint
|
|
93
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "provider_thread_id" text;--> statement-breakpoint
|
|
94
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "provider_turn_id" text;--> statement-breakpoint
|
|
95
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "provider_evidence" jsonb;--> statement-breakpoint
|
|
96
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "continuation_generation_id" uuid;--> statement-breakpoint
|
|
97
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "continuation_message_id" uuid;--> statement-breakpoint
|
|
98
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "delivery_lease_token" text;--> statement-breakpoint
|
|
99
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "delivery_lease_epoch" integer DEFAULT 0 NOT NULL;--> statement-breakpoint
|
|
100
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "delivery_lease_owner" text;--> statement-breakpoint
|
|
101
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "delivery_lease_expires_at" timestamp with time zone;--> statement-breakpoint
|
|
102
|
+
ALTER TABLE "chat_queued_messages" ADD COLUMN "reconciliation_reason" text;--> statement-breakpoint
|
|
103
|
+
ALTER TABLE "chat_control_actions" ADD CONSTRAINT "chat_control_actions_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
104
|
+
ALTER TABLE "chat_control_actions" ADD CONSTRAINT "chat_control_actions_expected_generation_id_chat_generations_id_fk" FOREIGN KEY ("expected_generation_id") REFERENCES "public"."chat_generations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
105
|
+
ALTER TABLE "chat_generation_events" ADD CONSTRAINT "chat_generation_events_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
106
|
+
ALTER TABLE "chat_generation_events" ADD CONSTRAINT "chat_generation_events_generation_id_chat_generations_id_fk" FOREIGN KEY ("generation_id") REFERENCES "public"."chat_generations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
107
|
+
ALTER TABLE "chat_generation_events" ADD CONSTRAINT "chat_generation_events_assistant_message_id_chat_messages_id_fk" FOREIGN KEY ("assistant_message_id") REFERENCES "public"."chat_messages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
108
|
+
ALTER TABLE "chat_generation_events" ADD CONSTRAINT "chat_generation_events_run_id_heartbeat_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."heartbeat_runs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
109
|
+
ALTER TABLE "chat_generation_events" ADD CONSTRAINT "chat_generation_events_control_action_id_chat_control_actions_id_fk" FOREIGN KEY ("control_action_id") REFERENCES "public"."chat_control_actions"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
110
|
+
ALTER TABLE "chat_generation_events" ADD CONSTRAINT "chat_generation_events_queue_item_id_chat_queued_messages_id_fk" FOREIGN KEY ("queue_item_id") REFERENCES "public"."chat_queued_messages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
111
|
+
ALTER TABLE "chat_generation_terminal_outbox" ADD CONSTRAINT "chat_generation_terminal_outbox_org_id_organizations_id_fk" FOREIGN KEY ("org_id") REFERENCES "public"."organizations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
112
|
+
ALTER TABLE "chat_generation_terminal_outbox" ADD CONSTRAINT "chat_generation_terminal_outbox_generation_id_chat_generations_id_fk" FOREIGN KEY ("generation_id") REFERENCES "public"."chat_generations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
113
|
+
ALTER TABLE "chat_generation_terminal_outbox" ADD CONSTRAINT "chat_generation_terminal_outbox_source_event_id_chat_generation_events_id_fk" FOREIGN KEY ("source_event_id") REFERENCES "public"."chat_generation_events"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
114
|
+
CREATE UNIQUE INDEX "chat_control_actions_org_action_uq" ON "chat_control_actions" USING btree ("org_id","id");--> statement-breakpoint
|
|
115
|
+
CREATE INDEX "chat_control_actions_generation_requested_idx" ON "chat_control_actions" USING btree ("expected_generation_id","requested_at");--> statement-breakpoint
|
|
116
|
+
CREATE INDEX "chat_control_actions_org_disposition_idx" ON "chat_control_actions" USING btree ("org_id","local_disposition","updated_at");--> statement-breakpoint
|
|
117
|
+
CREATE UNIQUE INDEX "chat_generation_events_generation_seq_uq" ON "chat_generation_events" USING btree ("generation_id","generation_seq");--> statement-breakpoint
|
|
118
|
+
CREATE INDEX "chat_generation_events_org_generation_seq_idx" ON "chat_generation_events" USING btree ("org_id","generation_id","generation_seq");--> statement-breakpoint
|
|
119
|
+
CREATE INDEX "chat_generation_events_assistant_message_idx" ON "chat_generation_events" USING btree ("assistant_message_id");--> statement-breakpoint
|
|
120
|
+
CREATE INDEX "chat_generation_events_run_idx" ON "chat_generation_events" USING btree ("run_id");--> statement-breakpoint
|
|
121
|
+
CREATE INDEX "chat_generation_events_control_action_idx" ON "chat_generation_events" USING btree ("control_action_id");--> statement-breakpoint
|
|
122
|
+
CREATE INDEX "chat_generation_events_queue_item_idx" ON "chat_generation_events" USING btree ("queue_item_id");--> statement-breakpoint
|
|
123
|
+
CREATE UNIQUE INDEX "chat_generation_terminal_outbox_generation_projection_uq" ON "chat_generation_terminal_outbox" USING btree ("generation_id","projection_version");--> statement-breakpoint
|
|
124
|
+
CREATE UNIQUE INDEX "chat_generation_terminal_outbox_source_event_uq" ON "chat_generation_terminal_outbox" USING btree ("source_event_id");--> statement-breakpoint
|
|
125
|
+
CREATE INDEX "chat_generation_terminal_outbox_claim_idx" ON "chat_generation_terminal_outbox" USING btree ("status","available_at","lease_expires_at");--> statement-breakpoint
|
|
126
|
+
CREATE INDEX "chat_generation_terminal_outbox_org_generation_idx" ON "chat_generation_terminal_outbox" USING btree ("org_id","generation_id");--> statement-breakpoint
|
|
127
|
+
ALTER TABLE "chat_queued_messages" ADD CONSTRAINT "chat_queued_messages_control_action_id_chat_control_actions_id_fk" FOREIGN KEY ("control_action_id") REFERENCES "public"."chat_control_actions"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
128
|
+
ALTER TABLE "chat_queued_messages" ADD CONSTRAINT "chat_queued_messages_continuation_generation_id_chat_generations_id_fk" FOREIGN KEY ("continuation_generation_id") REFERENCES "public"."chat_generations"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
129
|
+
ALTER TABLE "chat_queued_messages" ADD CONSTRAINT "chat_queued_messages_continuation_message_id_chat_messages_id_fk" FOREIGN KEY ("continuation_message_id") REFERENCES "public"."chat_messages"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
|
|
130
|
+
UPDATE "chat_generations" AS "generation"
|
|
131
|
+
SET
|
|
132
|
+
"status" = 'aborted',
|
|
133
|
+
"terminal_reason" = coalesce("generation"."terminal_reason", 'ownerless_during_durable_control_migration'),
|
|
134
|
+
"control_state" = 'terminal',
|
|
135
|
+
"runtime_terminal_at" = coalesce("generation"."runtime_terminal_at", now()),
|
|
136
|
+
"completed_at" = coalesce("generation"."completed_at", now()),
|
|
137
|
+
"updated_at" = now()
|
|
138
|
+
WHERE "generation"."status" IN ('starting', 'active', 'running', 'tool_busy', 'closing', 'stop_requested', 'stopping')
|
|
139
|
+
AND "generation"."control_owner_token" IS NULL;--> statement-breakpoint
|
|
140
|
+
UPDATE "chat_queued_messages"
|
|
141
|
+
SET
|
|
142
|
+
"status" = 'continuation_pending',
|
|
143
|
+
"delivery_intent" = 'steer',
|
|
144
|
+
"delivery_disposition" = 'continuation_pending',
|
|
145
|
+
"reconciliation_reason" = 'legacy_steer_recovered_on_upgrade',
|
|
146
|
+
"last_delivery_reason" = NULL,
|
|
147
|
+
"updated_at" = now()
|
|
148
|
+
WHERE "status" = 'steer_pending';--> statement-breakpoint
|
|
149
|
+
UPDATE "chat_queued_messages"
|
|
150
|
+
SET
|
|
151
|
+
"status" = 'queued',
|
|
152
|
+
"delivery_lease_token" = NULL,
|
|
153
|
+
"delivery_lease_owner" = NULL,
|
|
154
|
+
"delivery_lease_expires_at" = NULL,
|
|
155
|
+
"reconciliation_reason" = 'legacy_claim_released_on_upgrade',
|
|
156
|
+
"last_delivery_reason" = 'legacy_claim_released_on_upgrade',
|
|
157
|
+
"updated_at" = now()
|
|
158
|
+
WHERE "status" = 'dequeue_claimed';--> statement-breakpoint
|
|
159
|
+
UPDATE "chat_queued_messages"
|
|
160
|
+
SET
|
|
161
|
+
"status" = 'failed_actionable',
|
|
162
|
+
"delivery_disposition" = 'failed_actionable',
|
|
163
|
+
"reconciliation_reason" = 'legacy_running_delivery_unconfirmed_on_upgrade',
|
|
164
|
+
"last_delivery_reason" = 'legacy_running_delivery_unconfirmed_on_upgrade',
|
|
165
|
+
"updated_at" = now()
|
|
166
|
+
WHERE "status" = 'running';--> statement-breakpoint
|
|
167
|
+
CREATE UNIQUE INDEX "chat_generations_active_conversation_uq" ON "chat_generations" USING btree ("org_id","conversation_id") WHERE "chat_generations"."status" in ('starting', 'active', 'running', 'tool_busy', 'closing', 'stop_requested', 'stopping');--> statement-breakpoint
|
|
168
|
+
CREATE INDEX "chat_generations_control_lease_idx" ON "chat_generations" USING btree ("control_state","control_lease_expires_at");--> statement-breakpoint
|
|
169
|
+
CREATE UNIQUE INDEX "chat_queued_messages_control_action_uq" ON "chat_queued_messages" USING btree ("control_action_id");--> statement-breakpoint
|
|
170
|
+
CREATE UNIQUE INDEX "chat_queued_messages_continuation_generation_uq" ON "chat_queued_messages" USING btree ("continuation_generation_id");--> statement-breakpoint
|
|
171
|
+
CREATE UNIQUE INDEX "chat_queued_messages_continuation_message_uq" ON "chat_queued_messages" USING btree ("continuation_message_id");--> statement-breakpoint
|
|
172
|
+
CREATE INDEX "chat_queued_messages_delivery_claim_idx" ON "chat_queued_messages" USING btree ("org_id","status","delivery_lease_expires_at");--> statement-breakpoint
|
|
173
|
+
CREATE INDEX "chat_queued_messages_intent_position_idx" ON "chat_queued_messages" USING btree ("org_id","conversation_id","delivery_intent","status","position");
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
UPDATE "chat_queued_messages" AS "queue"
|
|
2
|
+
SET
|
|
3
|
+
"request_actor" = (
|
|
4
|
+
SELECT CASE
|
|
5
|
+
WHEN "activity"."actor_type" = 'agent' AND "activity"."agent_id" IS NOT NULL THEN
|
|
6
|
+
jsonb_strip_nulls(jsonb_build_object(
|
|
7
|
+
'type', 'agent',
|
|
8
|
+
'source', 'agent_key',
|
|
9
|
+
'orgId', "queue"."org_id"::text,
|
|
10
|
+
'agentId', "activity"."agent_id"::text,
|
|
11
|
+
'runId', "activity"."run_id"::text
|
|
12
|
+
))
|
|
13
|
+
WHEN "activity"."actor_type" = 'user' THEN
|
|
14
|
+
jsonb_strip_nulls(jsonb_build_object(
|
|
15
|
+
'type', 'board',
|
|
16
|
+
'source', 'session',
|
|
17
|
+
'userId', "activity"."actor_id",
|
|
18
|
+
'orgIds', jsonb_build_array("queue"."org_id"::text),
|
|
19
|
+
'isInstanceAdmin', false,
|
|
20
|
+
'runId', "activity"."run_id"::text
|
|
21
|
+
))
|
|
22
|
+
ELSE NULL
|
|
23
|
+
END
|
|
24
|
+
FROM "activity_log" AS "activity"
|
|
25
|
+
WHERE "activity"."org_id" = "queue"."org_id"
|
|
26
|
+
AND "activity"."action" = 'chat.queue.created'
|
|
27
|
+
AND "activity"."entity_type" = 'chat'
|
|
28
|
+
AND "activity"."entity_id" = "queue"."conversation_id"::text
|
|
29
|
+
AND "activity"."details"->>'queuedMessageId' = "queue"."id"::text
|
|
30
|
+
AND (
|
|
31
|
+
"activity"."actor_type" = 'user'
|
|
32
|
+
OR ("activity"."actor_type" = 'agent' AND "activity"."agent_id" IS NOT NULL)
|
|
33
|
+
)
|
|
34
|
+
ORDER BY "activity"."created_at" DESC, "activity"."id" DESC
|
|
35
|
+
LIMIT 1
|
|
36
|
+
),
|
|
37
|
+
"updated_at" = now()
|
|
38
|
+
WHERE ("queue"."request_actor" IS NULL OR "queue"."request_actor" = 'null'::jsonb)
|
|
39
|
+
AND "queue"."status" IN ('queued', 'steer_pending', 'continuation_pending', 'dequeue_claimed');--> statement-breakpoint
|
|
40
|
+
UPDATE "chat_queued_messages"
|
|
41
|
+
SET
|
|
42
|
+
"status" = 'queued',
|
|
43
|
+
"delivery_intent" = 'queue',
|
|
44
|
+
"delivery_disposition" = NULL,
|
|
45
|
+
"control_action_id" = NULL,
|
|
46
|
+
"delivery_lease_token" = NULL,
|
|
47
|
+
"delivery_lease_owner" = NULL,
|
|
48
|
+
"delivery_lease_expires_at" = NULL,
|
|
49
|
+
"reconciliation_reason" = 'legacy_request_actor_unavailable',
|
|
50
|
+
"last_delivery_reason" = 'legacy_request_actor_unavailable',
|
|
51
|
+
"version" = "version" + 1,
|
|
52
|
+
"updated_at" = now()
|
|
53
|
+
WHERE ("request_actor" IS NULL OR "request_actor" = 'null'::jsonb)
|
|
54
|
+
AND "status" IN ('queued', 'steer_pending', 'continuation_pending', 'dequeue_claimed');
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
ALTER TABLE "chat_conversations" ADD COLUMN "conversation_kind" text DEFAULT 'chat' NOT NULL;--> statement-breakpoint
|
|
2
|
+
ALTER TABLE "chat_conversations" ADD COLUMN "messenger_visible" boolean DEFAULT true NOT NULL;--> statement-breakpoint
|
|
3
|
+
ALTER TABLE "chat_conversations" ADD COLUMN "side_chat_state" text;--> statement-breakpoint
|
|
4
|
+
ALTER TABLE "chat_conversations" ADD COLUMN "side_chat_expires_at" timestamp with time zone;--> statement-breakpoint
|
|
5
|
+
ALTER TABLE "chat_conversations" ADD COLUMN "side_chat_completed_at" timestamp with time zone;--> statement-breakpoint
|
|
6
|
+
ALTER TABLE "chat_conversations" ADD COLUMN "side_chat_kept_at" timestamp with time zone;--> statement-breakpoint
|
|
7
|
+
ALTER TABLE "chat_conversations" ADD COLUMN "side_chat_client_mutation_id" text;--> statement-breakpoint
|
|
8
|
+
CREATE INDEX "chat_conversations_org_messenger_visibility_idx" ON "chat_conversations" USING btree ("org_id","messenger_visible","status","updated_at");--> statement-breakpoint
|
|
9
|
+
CREATE UNIQUE INDEX "chat_conversations_side_chat_owner_mutation_idx" ON "chat_conversations" USING btree ("org_id","created_by_user_id","side_chat_client_mutation_id");
|