@automagik/omni 2.260409.6 → 2.260421.3

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.
Files changed (53) hide show
  1. package/db/drizzle/0018_supreme_puma.sql +6 -0
  2. package/db/drizzle/0019_idle_chat_follow_up.sql +23 -0
  3. package/db/drizzle/0020_follow_up_config.sql +2 -0
  4. package/db/drizzle/0021_idle_follow_up_seed.sql +51 -0
  5. package/db/drizzle/0022_idle_follow_up_prompt_v2.sql +34 -0
  6. package/db/drizzle/0023_dispatcher_inbound_age.sql +8 -0
  7. package/db/drizzle/0024_quiet_gabe_jones.sql +23 -0
  8. package/db/drizzle/0025_panoramic_sinister_six.sql +5 -0
  9. package/db/drizzle/0026_agent_key_profiles.sql +19 -0
  10. package/db/drizzle/0027_bridge_tmux_session.sql +13 -0
  11. package/db/drizzle/meta/{0014_snapshot.json → 0018_snapshot.json} +678 -430
  12. package/db/drizzle/meta/{0013_snapshot.json → 0019_snapshot.json} +919 -445
  13. package/db/drizzle/meta/0020_snapshot.json +7240 -0
  14. package/db/drizzle/meta/0021_snapshot.json +7240 -0
  15. package/db/drizzle/meta/0024_snapshot.json +7240 -0
  16. package/db/drizzle/meta/0025_snapshot.json +7240 -0
  17. package/db/drizzle/meta/0026_snapshot.json +7274 -0
  18. package/db/drizzle/meta/_journal.json +70 -0
  19. package/dist/__tests__/mock-api.d.ts +24 -0
  20. package/dist/__tests__/mock-api.d.ts.map +1 -1
  21. package/dist/commands/agents.d.ts +2 -0
  22. package/dist/commands/agents.d.ts.map +1 -1
  23. package/dist/commands/doctor.d.ts +24 -15
  24. package/dist/commands/doctor.d.ts.map +1 -1
  25. package/dist/commands/events.d.ts +25 -0
  26. package/dist/commands/events.d.ts.map +1 -1
  27. package/dist/commands/follow-up.d.ts +13 -0
  28. package/dist/commands/follow-up.d.ts.map +1 -0
  29. package/dist/commands/install.d.ts +28 -29
  30. package/dist/commands/install.d.ts.map +1 -1
  31. package/dist/commands/instances.d.ts.map +1 -1
  32. package/dist/commands/keys.d.ts +43 -0
  33. package/dist/commands/keys.d.ts.map +1 -1
  34. package/dist/commands/start.d.ts.map +1 -1
  35. package/dist/commands/update.d.ts +12 -0
  36. package/dist/commands/update.d.ts.map +1 -1
  37. package/dist/commands/voice.d.ts +11 -0
  38. package/dist/commands/voice.d.ts.map +1 -0
  39. package/dist/config.d.ts +1 -1
  40. package/dist/config.d.ts.map +1 -1
  41. package/dist/index.js +94536 -65466
  42. package/dist/install-helpers.d.ts +32 -0
  43. package/dist/install-helpers.d.ts.map +1 -0
  44. package/dist/nats-install.d.ts +11 -0
  45. package/dist/nats-install.d.ts.map +1 -0
  46. package/dist/output.d.ts +14 -5
  47. package/dist/output.d.ts.map +1 -1
  48. package/dist/pm2.d.ts +46 -0
  49. package/dist/pm2.d.ts.map +1 -1
  50. package/dist/server/davey.linux-x64-gnu-vevevdy2.node +0 -0
  51. package/dist/server/davey.linux-x64-musl-3vkb94zg.node +0 -0
  52. package/dist/server/index.js +97148 -13518
  53. package/package.json +10 -10
@@ -0,0 +1,6 @@
1
+ ALTER TABLE "instances" RENAME COLUMN "gupshup_api_key" TO "gupshup_callback_url";
2
+ ALTER TABLE "instances" RENAME COLUMN "gupshup_app_name" TO "gupshup_auth_token";
3
+ ALTER TABLE "instances" RENAME COLUMN "gupshup_source_phone" TO "gupshup_event_id";
4
+ ALTER TABLE "instances" ALTER COLUMN "gupshup_callback_url" SET DATA TYPE text;
5
+ ALTER TABLE "instances" ALTER COLUMN "gupshup_auth_token" SET DATA TYPE text;
6
+ ALTER TABLE "instances" ALTER COLUMN "gupshup_event_id" SET DATA TYPE varchar(255);
@@ -0,0 +1,23 @@
1
+ CREATE TABLE "chat_follow_up_state" (
2
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3
+ "chat_id" uuid NOT NULL,
4
+ "instance_id" uuid NOT NULL,
5
+ "agent_id" uuid,
6
+ "sequence_config" jsonb NOT NULL,
7
+ "sequence_index" integer DEFAULT 0 NOT NULL,
8
+ "last_agent_message_at" timestamp with time zone NOT NULL,
9
+ "last_inbound_customer_message_at" timestamp with time zone,
10
+ "next_fire_at" timestamp with time zone,
11
+ "disarm_reason" varchar(32),
12
+ "disarmed_at" timestamp with time zone,
13
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
14
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
15
+ );
16
+ --> statement-breakpoint
17
+ ALTER TABLE "chat_follow_up_state" ADD CONSTRAINT "chat_follow_up_state_chat_id_chats_id_fk" FOREIGN KEY ("chat_id") REFERENCES "public"."chats"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
18
+ ALTER TABLE "chat_follow_up_state" ADD CONSTRAINT "chat_follow_up_state_instance_id_instances_id_fk" FOREIGN KEY ("instance_id") REFERENCES "public"."instances"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
19
+ ALTER TABLE "chat_follow_up_state" ADD CONSTRAINT "chat_follow_up_state_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
20
+ CREATE INDEX "chat_follow_up_state_sweeper_idx" ON "chat_follow_up_state" USING btree ("next_fire_at","disarm_reason");--> statement-breakpoint
21
+ CREATE UNIQUE INDEX "chat_follow_up_state_chat_instance_unique" ON "chat_follow_up_state" USING btree ("chat_id","instance_id");--> statement-breakpoint
22
+ CREATE INDEX "chat_follow_up_state_chat_idx" ON "chat_follow_up_state" USING btree ("chat_id");--> statement-breakpoint
23
+ CREATE INDEX "chat_follow_up_state_instance_idx" ON "chat_follow_up_state" USING btree ("instance_id");
@@ -0,0 +1,2 @@
1
+ ALTER TABLE "agents" ADD COLUMN "follow_up_config" jsonb;--> statement-breakpoint
2
+ ALTER TABLE "instances" ADD COLUMN "follow_up_config" jsonb;
@@ -0,0 +1,51 @@
1
+ -- Seed the default idle-chat follow-up automation.
2
+ -- The follow-up sweeper publishes `chat.idle_timeout`; without an
3
+ -- automation subscribed to that event, arming is a no-op in production.
4
+ -- Source of truth for the structure lives at
5
+ -- docs/examples/automations/idle-follow-up.yaml.
6
+
7
+ INSERT INTO "automations" (
8
+ "id",
9
+ "name",
10
+ "description",
11
+ "trigger_event_type",
12
+ "trigger_conditions",
13
+ "condition_logic",
14
+ "actions",
15
+ "enabled",
16
+ "priority",
17
+ "created_at",
18
+ "updated_at"
19
+ )
20
+ SELECT
21
+ '00000000-0000-4000-8000-000000000f04'::uuid,
22
+ 'Idle chat follow-up',
23
+ 'Ask the agent to draft a follow-up when a customer goes idle after an agent reply. Paired with per-agent/per-instance follow-up config (see omni follow-up set ...).',
24
+ 'chat.idle_timeout',
25
+ '[]'::jsonb,
26
+ 'and',
27
+ '[
28
+ {
29
+ "type": "call_agent",
30
+ "config": {
31
+ "agentId": "{{payload.agentId}}",
32
+ "promptOverride": "The customer has been idle for {{minutes}} minutes since your last reply. This is follow-up #{{sequenceIndex}} in the sequence.\n\n{{syntheticPrompt}}\n\nWrite a short, warm follow-up message to {{chatName}} in their preferred language. Do not mention that this is an automated follow-up.",
33
+ "responseAs": "followUpReply"
34
+ }
35
+ },
36
+ {
37
+ "type": "send_message",
38
+ "config": {
39
+ "instanceId": "{{payload.instanceId}}",
40
+ "to": "{{payload.chatId}}",
41
+ "contentTemplate": "{{followUpReply}}"
42
+ }
43
+ }
44
+ ]'::jsonb,
45
+ true,
46
+ 100,
47
+ NOW(),
48
+ NOW()
49
+ WHERE NOT EXISTS (
50
+ SELECT 1 FROM "automations" WHERE "name" = 'Idle chat follow-up'
51
+ );
@@ -0,0 +1,34 @@
1
+ -- Upgrade the "Idle chat follow-up" automation promptOverride to use
2
+ -- 1-based `{{attemptNumber}}` / `{{totalAttempts}}` placeholders instead of the
3
+ -- zero-based `{{sequenceIndex}}`.
4
+ --
5
+ -- Context: in production the agent was reading "This is follow-up #0" and
6
+ -- confusing itself into emitting meta-commentary ("_(limite atingido)_") from
7
+ -- its own session memory. The new wrapper uses natural 1-based numbering and
8
+ -- explicitly forbids stage directions / parenthetical notes.
9
+ --
10
+ -- Idempotent: only rewrites the built-in row. User-authored automations are
11
+ -- untouched.
12
+
13
+ UPDATE "automations"
14
+ SET
15
+ "actions" = '[
16
+ {
17
+ "type": "call_agent",
18
+ "config": {
19
+ "agentId": "{{payload.agentId}}",
20
+ "promptOverride": "Follow-up context: attempt {{attemptNumber}} of {{totalAttempts}} — {{minutes}} minutes of silence since your last message to {{chatName}}.\n\n{{syntheticPrompt}}\n\nRespond with ONLY the customer-facing message. Plain text, no italics, no parentheses, no stage directions, no meta-commentary. Do not refer to yourself as an automation or follow-up bot.",
21
+ "responseAs": "followUpReply"
22
+ }
23
+ },
24
+ {
25
+ "type": "send_message",
26
+ "config": {
27
+ "instanceId": "{{payload.instanceId}}",
28
+ "to": "{{payload.chatId}}",
29
+ "contentTemplate": "{{followUpReply}}"
30
+ }
31
+ }
32
+ ]'::jsonb,
33
+ "updated_at" = NOW()
34
+ WHERE "id" = '00000000-0000-4000-8000-000000000f04'::uuid;
@@ -0,0 +1,8 @@
1
+ -- Add `inbound_max_age_minutes` to `instances`. Drops inbound
2
+ -- `message.received` events for the agent dispatcher when the platform-native
3
+ -- timestamp (e.g. WhatsApp `messageTimestamp`) is older than this value.
4
+ --
5
+ -- Guards against history-sync replays and NATS redelivery of stale messages
6
+ -- after reconnect/restart. Default: 10 minutes.
7
+
8
+ ALTER TABLE "instances" ADD COLUMN "inbound_max_age_minutes" integer DEFAULT 10 NOT NULL;
@@ -0,0 +1,23 @@
1
+ -- Add `handoff_logs` table to persist every agent→human handoff with full payload.
2
+ -- Records instanceId, chatId, toPhone, text, extraInfo, agentId, and externalMessageId
3
+ -- so handoffs can be queried, audited, and correlated with omni_events.
4
+
5
+ CREATE TABLE "handoff_logs" (
6
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
7
+ "instance_id" uuid REFERENCES "instances"("id") ON DELETE SET NULL,
8
+ "chat_uuid" uuid REFERENCES "chats"("id") ON DELETE SET NULL,
9
+ "chat_id" varchar(255) NOT NULL,
10
+ "to_phone" varchar(100) NOT NULL,
11
+ "text" text NOT NULL,
12
+ "extra_info" text,
13
+ "agent_id" uuid REFERENCES "agents"("id") ON DELETE SET NULL,
14
+ "external_message_id" varchar(255),
15
+ "sent_at" timestamp DEFAULT now() NOT NULL,
16
+ "metadata" jsonb
17
+ );
18
+
19
+ CREATE INDEX "handoff_logs_instance_idx" ON "handoff_logs" ("instance_id");
20
+ CREATE INDEX "handoff_logs_chat_uuid_idx" ON "handoff_logs" ("chat_uuid");
21
+ CREATE INDEX "handoff_logs_chat_id_idx" ON "handoff_logs" ("chat_id");
22
+ CREATE INDEX "handoff_logs_sent_at_idx" ON "handoff_logs" ("sent_at");
23
+ CREATE INDEX "handoff_logs_agent_idx" ON "handoff_logs" ("agent_id");
@@ -0,0 +1,5 @@
1
+ -- Add `handoff_fields` jsonb column to `handoff_logs`.
2
+ -- Stores structured key-value pairs from the agent for Gupshup flow variable mapping
3
+ -- (e.g. nome → var_global.name, temperatura_lead → var_global.calor_do_lead).
4
+
5
+ ALTER TABLE "handoff_logs" ADD COLUMN "handoff_fields" jsonb;
@@ -0,0 +1,19 @@
1
+ -- Omni scope profiles: add profile + allowlist columns to `api_keys`.
2
+ --
3
+ -- Existing keys are backfilled as follows:
4
+ -- * `profile` stays NULL — they keep their hand-authored `scopes`
5
+ -- * `profile_overrides` defaults to `'{}'::jsonb`
6
+ -- * `chat_allowlist` / `instance_allowlist` / `outbound_recipient_allowlist`
7
+ -- default to empty arrays. For NULL-profile keys the enforcer treats `[]`
8
+ -- as "no lock" (backward compat). For profile keys that declare
9
+ -- `requiresLocks`, `[]` means "deny all" — see docs/profiles.md.
10
+
11
+ ALTER TABLE "api_keys" ADD COLUMN "profile" varchar(32);
12
+ --> statement-breakpoint
13
+ ALTER TABLE "api_keys" ADD COLUMN "profile_overrides" jsonb DEFAULT '{}'::jsonb NOT NULL;
14
+ --> statement-breakpoint
15
+ ALTER TABLE "api_keys" ADD COLUMN "chat_allowlist" text[] DEFAULT ARRAY[]::text[] NOT NULL;
16
+ --> statement-breakpoint
17
+ ALTER TABLE "api_keys" ADD COLUMN "instance_allowlist" uuid[] DEFAULT ARRAY[]::uuid[] NOT NULL;
18
+ --> statement-breakpoint
19
+ ALTER TABLE "api_keys" ADD COLUMN "outbound_recipient_allowlist" text[] DEFAULT ARRAY[]::text[] NOT NULL;
@@ -0,0 +1,13 @@
1
+ -- Per-instance bridge tmux session override for the genie `nats-genie` provider.
2
+ --
3
+ -- When set, the provider propagates this value via the NATS message env as
4
+ -- `GENIE_TMUX_SESSION`; the consumer genie bridge uses it as the highest-
5
+ -- priority override in its three-layer tmux-session resolution chain.
6
+ -- NULL keeps today's behavior (no override, genie falls back to agent-level
7
+ -- or name-based defaults).
8
+ --
9
+ -- Enables one-agent-many-instances fan-out — e.g. a single "scout" agent
10
+ -- hooked to N inbound numbers lands each instance's dispatches in its own
11
+ -- tmux session for isolation and live-intelligence observability.
12
+
13
+ ALTER TABLE "instances" ADD COLUMN "bridge_tmux_session" text;