Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(feishu): 通知话题回复继续原任务

liugaowei0e2e6a268ff7
diff --git a/apps/desktop/drizzle/0107_sudden_ultron.sql b/apps/desktop/drizzle/0107_sudden_ultron.sql
new file mode 100644
index 0000000000..2908ca53da
--- /dev/null
+++ b/apps/desktop/drizzle/0107_sudden_ultron.sql
@@ -0,0 +1,10 @@
+CREATE TABLE `im_notification_origins` (
+ `channel` text NOT NULL,
+ `bot_context_id` text NOT NULL,
+ `user_id` text NOT NULL,
+ `message_id` text NOT NULL,
+ `chat_id` text NOT NULL,
+ `session_id` text NOT NULL,
+ `created_at` integer NOT NULL,
+ PRIMARY KEY(`channel`, `bot_context_id`, `user_id`, `message_id`)
+);
diff --git a/apps/desktop/drizzle/meta/0107_snapshot.json b/apps/desktop/drizzle/meta/0107_snapshot.json
new file mode 100644
index 0000000000..69d8dcf925
--- /dev/null
+++ b/apps/desktop/drizzle/meta/0107_snapshot.json
@@ -0,0 +1,5864 @@
+{
+ "version": "6",
+ "dialect": "sqlite",
+ "id": "2b3f067d-99f9-4f3c-b8cc-c4fed9500a71",
+ "prevId": "0f13f9e7-9393-4f45-9e45-7747add59383",
+ "tables": {
+ "account_usage_snapshots": {
+ "name": "account_usage_snapshots",
+ "columns": {
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "snapshot": {
+ "name": "snapshot",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "agent_input_queue_snapshots": {
+ "name": "agent_input_queue_snapshots",
+ "columns": {
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "payload": {
+ "name": "payload",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {
+ "agent_input_queue_snapshots_session_id_sessions_id_fk": {
+ "name": "agent_input_queue_snapshots_session_id_sessions_id_fk",
+ "tableFrom": "agent_input_queue_snapshots",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_delegations": {
+ "name": "bot_delegations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "requesting_bot_id": {
+ "name": "requesting_bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "target_bot_id": {
+ "name": "target_bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "parent_session_id": {
+ "name": "parent_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "child_session_id": {
+ "name": "child_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "objective": {
+ "name": "objective",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "context_refs_json": {
+ "name": "context_refs_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "artifact_refs_json": {
+ "name": "artifact_refs_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "permission_snapshot_json": {
+ "name": "permission_snapshot_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "lineage_json": {
+ "name": "lineage_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "target_profile_version": {
+ "name": "target_profile_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "depth": {
+ "name": "depth",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "budget_tokens": {
+ "name": "budget_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "tokens_used": {
+ "name": "tokens_used",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'queued'"
+ },
+ "result_summary": {
+ "name": "result_summary",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "output_artifacts_json": {
+ "name": "output_artifacts_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "pending_interaction_json": {
+ "name": "pending_interaction_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "run_sequence": {
+ "name": "run_sequence",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "accepted_at": {
+ "name": "accepted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "completed_at": {
+ "name": "completed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "completion_delivered_at": {
+ "name": "completion_delivered_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_bot_delegations_requester_status": {
+ "name": "idx_bot_delegations_requester_status",
+ "columns": [
+ "requesting_bot_id",
+ "status"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_delegations_target_status": {
+ "name": "idx_bot_delegations_target_status",
+ "columns": [
+ "target_bot_id",
+ "status"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_delegations_parent_session": {
+ "name": "idx_bot_delegations_parent_session",
+ "columns": [
+ "parent_session_id"
+ ],
+ "isUnique": false
+ },
+ "uniq_bot_delegations_child_session": {
+ "name": "uniq_bot_delegations_child_session",
+ "columns": [
+ "child_session_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "bot_delegations_requesting_bot_id_bot_profiles_id_fk": {
+ "name": "bot_delegations_requesting_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_delegations",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "requesting_bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_delegations_target_bot_id_bot_profiles_id_fk": {
+ "name": "bot_delegations_target_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_delegations",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "target_bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_delegations_parent_session_id_sessions_id_fk": {
+ "name": "bot_delegations_parent_session_id_sessions_id_fk",
+ "tableFrom": "bot_delegations",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "parent_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "bot_delegations_child_session_id_sessions_id_fk": {
+ "name": "bot_delegations_child_session_id_sessions_id_fk",
+ "tableFrom": "bot_delegations",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "child_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_direct_message_threads": {
+ "name": "bot_direct_message_threads",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_a_id": {
+ "name": "bot_a_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_b_id": {
+ "name": "bot_b_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "close_reason": {
+ "name": "close_reason",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "message_count": {
+ "name": "message_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "max_messages": {
+ "name": "max_messages",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "blocked_until": {
+ "name": "blocked_until",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "closed_at": {
+ "name": "closed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_bot_dm_threads_active_pair": {
+ "name": "uniq_bot_dm_threads_active_pair",
+ "columns": [
+ "bot_a_id",
+ "bot_b_id"
+ ],
+ "isUnique": true,
+ "where": "\"bot_direct_message_threads\".\"status\" = 'active'"
+ },
+ "idx_bot_dm_threads_pair_updated": {
+ "name": "idx_bot_dm_threads_pair_updated",
+ "columns": [
+ "bot_a_id",
+ "bot_b_id",
+ "updated_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_direct_message_threads_bot_a_id_bot_profiles_id_fk": {
+ "name": "bot_direct_message_threads_bot_a_id_bot_profiles_id_fk",
+ "tableFrom": "bot_direct_message_threads",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_a_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_direct_message_threads_bot_b_id_bot_profiles_id_fk": {
+ "name": "bot_direct_message_threads_bot_b_id_bot_profiles_id_fk",
+ "tableFrom": "bot_direct_message_threads",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_b_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_direct_messages": {
+ "name": "bot_direct_messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "thread_id": {
+ "name": "thread_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sequence": {
+ "name": "sequence",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sender_bot_id": {
+ "name": "sender_bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "recipient_bot_id": {
+ "name": "recipient_bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sender_session_id": {
+ "name": "sender_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "recipient_session_id": {
+ "name": "recipient_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "delivery_status": {
+ "name": "delivery_status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_bot_direct_messages_thread_sequence": {
+ "name": "uniq_bot_direct_messages_thread_sequence",
+ "columns": [
+ "thread_id",
+ "sequence"
+ ],
+ "isUnique": true
+ },
+ "idx_bot_direct_messages_thread_created": {
+ "name": "idx_bot_direct_messages_thread_created",
+ "columns": [
+ "thread_id",
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_direct_messages_thread_id_bot_direct_message_threads_id_fk": {
+ "name": "bot_direct_messages_thread_id_bot_direct_message_threads_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "bot_direct_message_threads",
+ "columnsFrom": [
+ "thread_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_direct_messages_sender_bot_id_bot_profiles_id_fk": {
+ "name": "bot_direct_messages_sender_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "sender_bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_direct_messages_recipient_bot_id_bot_profiles_id_fk": {
+ "name": "bot_direct_messages_recipient_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "recipient_bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_direct_messages_sender_session_id_sessions_id_fk": {
+ "name": "bot_direct_messages_sender_session_id_sessions_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "sender_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "bot_direct_messages_recipient_session_id_sessions_id_fk": {
+ "name": "bot_direct_messages_recipient_session_id_sessions_id_fk",
+ "tableFrom": "bot_direct_messages",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "recipient_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_lifecycle_events": {
+ "name": "bot_lifecycle_events",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_id": {
+ "name": "bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "event_type": {
+ "name": "event_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "payload_json": {
+ "name": "payload_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_bot_lifecycle_events_bot_created": {
+ "name": "idx_bot_lifecycle_events_bot_created",
+ "columns": [
+ "bot_id",
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_lifecycle_events_session_created": {
+ "name": "idx_bot_lifecycle_events_session_created",
+ "columns": [
+ "session_id",
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_lifecycle_events_bot_id_bot_profiles_id_fk": {
+ "name": "bot_lifecycle_events_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_lifecycle_events",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_lifecycle_events_session_id_sessions_id_fk": {
+ "name": "bot_lifecycle_events_session_id_sessions_id_fk",
+ "tableFrom": "bot_lifecycle_events",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_profile_versions": {
+ "name": "bot_profile_versions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_id": {
+ "name": "bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "version": {
+ "name": "version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "identity_source": {
+ "name": "identity_source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "capabilities_json": {
+ "name": "capabilities_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_bot_profile_versions_bot_version": {
+ "name": "uniq_bot_profile_versions_bot_version",
+ "columns": [
+ "bot_id",
+ "version"
+ ],
+ "isUnique": true
+ },
+ "idx_bot_profile_versions_bot_created": {
+ "name": "idx_bot_profile_versions_bot_created",
+ "columns": [
+ "bot_id",
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_profile_versions_bot_id_bot_profiles_id_fk": {
+ "name": "bot_profile_versions_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_profile_versions",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_profiles": {
+ "name": "bot_profiles",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "display_name": {
+ "name": "display_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "avatar": {
+ "name": "avatar",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'🤖'"
+ },
+ "avatar_color": {
+ "name": "avatar_color",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'violet'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "hidden_at": {
+ "name": "hidden_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "pinned_at": {
+ "name": "pinned_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "attention_reason": {
+ "name": "attention_reason",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "attention_at": {
+ "name": "attention_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "current_version": {
+ "name": "current_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "canonical_session_id": {
+ "name": "canonical_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_bot_profiles_status_updated": {
+ "name": "idx_bot_profiles_status_updated",
+ "columns": [
+ "status",
+ "updated_at"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_profiles_canonical_session": {
+ "name": "idx_bot_profiles_canonical_session",
+ "columns": [
+ "canonical_session_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_profiles_canonical_session_id_sessions_id_fk": {
+ "name": "bot_profiles_canonical_session_id_sessions_id_fk",
+ "tableFrom": "bot_profiles",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "canonical_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_runtime_snapshots": {
+ "name": "bot_runtime_snapshots",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_id": {
+ "name": "bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "profile_version": {
+ "name": "profile_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "working_dir": {
+ "name": "working_dir",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "memory_scope_key": {
+ "name": "memory_scope_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "configured_json": {
+ "name": "configured_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "resolved_json": {
+ "name": "resolved_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "prepared_at": {
+ "name": "prepared_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "applied_at": {
+ "name": "applied_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "failed_at": {
+ "name": "failed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "failure_json": {
+ "name": "failure_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_bot_runtime_snapshots_bot_prepared": {
+ "name": "idx_bot_runtime_snapshots_bot_prepared",
+ "columns": [
+ "bot_id",
+ "prepared_at"
+ ],
+ "isUnique": false
+ },
+ "idx_bot_runtime_snapshots_session_prepared": {
+ "name": "idx_bot_runtime_snapshots_session_prepared",
+ "columns": [
+ "session_id",
+ "prepared_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_runtime_snapshots_bot_id_bot_profiles_id_fk": {
+ "name": "bot_runtime_snapshots_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_runtime_snapshots",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_runtime_snapshots_session_id_sessions_id_fk": {
+ "name": "bot_runtime_snapshots_session_id_sessions_id_fk",
+ "tableFrom": "bot_runtime_snapshots",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "bot_session_links": {
+ "name": "bot_session_links",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_id": {
+ "name": "bot_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "profile_version": {
+ "name": "profile_version",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "route_key": {
+ "name": "route_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "archived_at": {
+ "name": "archived_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_bot_session_links_session": {
+ "name": "uniq_bot_session_links_session",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": true
+ },
+ "uniq_bot_session_links_canonical_per_bot": {
+ "name": "uniq_bot_session_links_canonical_per_bot",
+ "columns": [
+ "bot_id"
+ ],
+ "isUnique": true,
+ "where": "\"bot_session_links\".\"role\" = 'canonical'"
+ },
+ "idx_bot_session_links_bot_role": {
+ "name": "idx_bot_session_links_bot_role",
+ "columns": [
+ "bot_id",
+ "role"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "bot_session_links_bot_id_bot_profiles_id_fk": {
+ "name": "bot_session_links_bot_id_bot_profiles_id_fk",
+ "tableFrom": "bot_session_links",
+ "tableTo": "bot_profiles",
+ "columnsFrom": [
+ "bot_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "bot_session_links_session_id_sessions_id_fk": {
+ "name": "bot_session_links_session_id_sessions_id_fk",
+ "tableFrom": "bot_session_links",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "custom_mcp_servers": {
+ "name": "custom_mcp_servers",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "transport": {
+ "name": "transport",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "headers": {
+ "name": "headers",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "sort_order": {
+ "name": "sort_order",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_custom_mcp_servers_sort_order": {
+ "name": "idx_custom_mcp_servers_sort_order",
+ "columns": [
+ "sort_order"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "custom_providers": {
+ "name": "custom_providers",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "runtimes": {
+ "name": "runtimes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "auth": {
+ "name": "auth",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "sort_order": {
+ "name": "sort_order",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_custom_providers_sort_order": {
+ "name": "idx_custom_providers_sort_order",
+ "columns": [
+ "sort_order"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "daily_model_usage": {
+ "name": "daily_model_usage",
+ "columns": {
+ "day": {
+ "name": "day",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cost_usd": {
+ "name": "cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_amount": {
+ "name": "cost_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_currency": {
+ "name": "cost_currency",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'USD'"
+ },
+ "cost_is_approximate": {
+ "name": "cost_is_approximate",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "input_tokens": {
+ "name": "input_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "output_tokens": {
+ "name": "output_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cache_read_tokens": {
+ "name": "cache_read_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cache_create_tokens": {
+ "name": "cache_create_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "daily_model_usage_day_agent_kind_model_cost_currency_pk": {
+ "columns": [
+ "day",
+ "agent_kind",
+ "model",
+ "cost_currency"
+ ],
+ "name": "daily_model_usage_day_agent_kind_model_cost_currency_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "daily_spend": {
+ "name": "daily_spend",
+ "columns": {
+ "day": {
+ "name": "day",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cost_usd": {
+ "name": "cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_amount": {
+ "name": "cost_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_currency": {
+ "name": "cost_currency",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'USD'"
+ },
+ "cost_is_approximate": {
+ "name": "cost_is_approximate",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "daily_spend_day_cost_currency_pk": {
+ "columns": [
+ "day",
+ "cost_currency"
+ ],
+ "name": "daily_spend_day_cost_currency_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "device_link_ownership": {
+ "name": "device_link_ownership",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner_id": {
+ "name": "owner_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner_pid": {
+ "name": "owner_pid",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner_label": {
+ "name": "owner_label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "heartbeat_at": {
+ "name": "heartbeat_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "embedding_jobs": {
+ "name": "embedding_jobs",
+ "columns": {
+ "rowid": {
+ "name": "rowid",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "source_id": {
+ "name": "source_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chunk_index": {
+ "name": "chunk_index",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "model_id": {
+ "name": "model_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "vec_table": {
+ "name": "vec_table",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "last_error": {
+ "name": "last_error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "scheduled_at": {
+ "name": "scheduled_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "locked_at": {
+ "name": "locked_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_embedding_jobs_natural": {
+ "name": "uniq_embedding_jobs_natural",
+ "columns": [
+ "source",
+ "source_id",
+ "chunk_index",
+ "model_id"
+ ],
+ "isUnique": true
+ },
+ "idx_embedding_jobs_status_scheduled": {
+ "name": "idx_embedding_jobs_status_scheduled",
+ "columns": [
+ "status",
+ "scheduled_at"
+ ],
+ "isUnique": false
+ },
+ "idx_embedding_jobs_source_id": {
+ "name": "idx_embedding_jobs_source_id",
+ "columns": [
+ "source",
+ "source_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "embedding_meta": {
+ "name": "embedding_meta",
+ "columns": {
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "ghost_cards": {
+ "name": "ghost_cards",
+ "columns": {
+ "call_id": {
+ "name": "call_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ghost_id": {
+ "name": "ghost_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "html": {
+ "name": "html",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "height": {
+ "name": "height",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "v": {
+ "name": "v",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 1
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "ghost_cards_updated_at_idx": {
+ "name": "ghost_cards_updated_at_idx",
+ "columns": [
+ "updated_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "hook_group_context_cursors": {
+ "name": "hook_group_context_cursors",
+ "columns": {
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cursor_key": {
+ "name": "cursor_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "cursor_id": {
+ "name": "cursor_id",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "hook_group_context_cursors_updated_at_idx": {
+ "name": "hook_group_context_cursors_updated_at_idx",
+ "columns": [
+ "updated_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "hook_group_context_cursors_provider_cursor_key_pk": {
+ "columns": [
+ "provider",
+ "cursor_key"
+ ],
+ "name": "hook_group_context_cursors_provider_cursor_key_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "hook_group_message_stats": {
+ "name": "hook_group_message_stats",
+ "columns": {
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "row_count": {
+ "name": "row_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "text_bytes": {
+ "name": "text_bytes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "hook_group_messages": {
+ "name": "hook_group_messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chat_id": {
+ "name": "chat_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "thread_id": {
+ "name": "thread_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chat_name": {
+ "name": "chat_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "author": {
+ "name": "author",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_bot": {
+ "name": "is_bot",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "text": {
+ "name": "text",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "file_names": {
+ "name": "file_names",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "sent_at": {
+ "name": "sent_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "hook_group_messages_msg_idx": {
+ "name": "hook_group_messages_msg_idx",
+ "columns": [
+ "provider",
+ "chat_id",
+ "thread_id",
+ "message_id"
+ ],
+ "isUnique": true
+ },
+ "hook_group_messages_window_idx": {
+ "name": "hook_group_messages_window_idx",
+ "columns": [
+ "provider",
+ "chat_id",
+ "thread_id",
+ "id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "im_bindings": {
+ "name": "im_bindings",
+ "columns": {
+ "channel": {
+ "name": "channel",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_context_id": {
+ "name": "bot_context_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "scope_key": {
+ "name": "scope_key",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "target_session_id": {
+ "name": "target_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "attached_at": {
+ "name": "attached_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "attached_via_card_message_id": {
+ "name": "attached_via_card_message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_im_bindings_target": {
+ "name": "idx_im_bindings_target",
+ "columns": [
+ "target_session_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "im_bindings_target_session_id_sessions_id_fk": {
+ "name": "im_bindings_target_session_id_sessions_id_fk",
+ "tableFrom": "im_bindings",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "target_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "im_bindings_channel_bot_context_id_user_id_scope_key_pk": {
+ "columns": [
+ "channel",
+ "bot_context_id",
+ "user_id",
+ "scope_key"
+ ],
+ "name": "im_bindings_channel_bot_context_id_user_id_scope_key_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "im_notification_origins": {
+ "name": "im_notification_origins",
+ "columns": {
+ "channel": {
+ "name": "channel",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bot_context_id": {
+ "name": "bot_context_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "user_id": {
+ "name": "user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chat_id": {
+ "name": "chat_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {
+ "im_notification_origins_channel_bot_context_id_user_id_message_id_pk": {
+ "columns": [
+ "channel",
+ "bot_context_id",
+ "user_id",
+ "message_id"
+ ],
+ "name": "im_notification_origins_channel_bot_context_id_user_id_message_id_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "media_blobs": {
+ "name": "media_blobs",
+ "columns": {
+ "hash": {
+ "name": "hash",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ext": {
+ "name": "ext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mime_type": {
+ "name": "mime_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bytes": {
+ "name": "bytes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_cache": {
+ "name": "is_cache",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_access_at": {
+ "name": "last_access_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "media_invocations": {
+ "name": "media_invocations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner": {
+ "name": "owner",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "model_id": {
+ "name": "model_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "capability": {
+ "name": "capability",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "guide_revision": {
+ "name": "guide_revision",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "guide_json": {
+ "name": "guide_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "state": {
+ "name": "state",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "response_json": {
+ "name": "response_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "media_invocations_owner_created_at_idx": {
+ "name": "media_invocations_owner_created_at_idx",
+ "columns": [
+ "owner",
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "media_invocations_owner_state_idx": {
+ "name": "media_invocations_owner_state_idx",
+ "columns": [
+ "owner",
+ "state"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "media_refs": {
+ "name": "media_refs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "hash": {
+ "name": "hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ref_kind": {
+ "name": "ref_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ref_id": {
+ "name": "ref_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "origin_session_id": {
+ "name": "origin_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "origin_kind": {
+ "name": "origin_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "origin_id": {
+ "name": "origin_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "media_refs_hash_idx": {
+ "name": "media_refs_hash_idx",
+ "columns": [
+ "hash"
+ ],
+ "isUnique": false
+ },
+ "media_refs_ref_idx": {
+ "name": "media_refs_ref_idx",
+ "columns": [
+ "ref_kind",
+ "ref_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "media_refs_hash_media_blobs_hash_fk": {
+ "name": "media_refs_hash_media_blobs_hash_fk",
+ "tableFrom": "media_refs",
+ "tableTo": "media_blobs",
+ "columnsFrom": [
+ "hash"
+ ],
+ "columnsTo": [
+ "hash"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "messages": {
+ "name": "messages",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "content": {
+ "name": "content",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tool_use_id": {
+ "name": "tool_use_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_meta": {
+ "name": "agent_meta",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "rewind_at": {
+ "name": "rewind_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_messages_session_client": {
+ "name": "uniq_messages_session_client",
+ "columns": [
+ "session_id",
+ "client_id"
+ ],
+ "isUnique": true
+ },
+ "idx_messages_session_created": {
+ "name": "idx_messages_session_created",
+ "columns": [
+ "session_id",
+ "created_at"
+ ],
+ "isUnique": false
+ },
+ "idx_messages_created_at": {
+ "name": "idx_messages_created_at",
+ "columns": [
+ "created_at",
+ "id"
+ ],
+ "isUnique": false
+ },
+ "idx_messages_rewind_at": {
+ "name": "idx_messages_rewind_at",
+ "columns": [
+ "rewind_at"
+ ],
+ "isUnique": false
+ },
+ "idx_messages_active_error_tail": {
+ "name": "idx_messages_active_error_tail",
+ "columns": [
+ "session_id",
+ "created_at"
+ ],
+ "isUnique": false,
+ "where": "\"messages\".\"role\" = 'error' AND \"messages\".\"rewind_at\" IS NULL"
+ }
+ },
+ "foreignKeys": {
+ "messages_session_id_sessions_id_fk": {
+ "name": "messages_session_id_sessions_id_fk",
+ "tableFrom": "messages",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "messages_fts_rows": {
+ "name": "messages_fts_rows",
+ "columns": {
+ "fts_rowid": {
+ "name": "fts_rowid",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": true
+ },
+ "message_id": {
+ "name": "message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "messages_fts_rows_message_id_idx": {
+ "name": "messages_fts_rows_message_id_idx",
+ "columns": [
+ "message_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "migration_history": {
+ "name": "migration_history",
+ "columns": {
+ "seq": {
+ "name": "seq",
+ "type": "integer",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "file_name": {
+ "name": "file_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "content_hash": {
+ "name": "content_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "applied_at": {
+ "name": "applied_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "migration_meta": {
+ "name": "migration_meta",
+ "columns": {
+ "key": {
+ "name": "key",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "value": {
+ "name": "value",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "orca_teams": {
+ "name": "orca_teams",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "lead_session_id": {
+ "name": "lead_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "completed_at": {
+ "name": "completed_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_active_team_per_lead": {
+ "name": "uniq_active_team_per_lead",
+ "columns": [
+ "lead_session_id"
+ ],
+ "isUnique": true,
+ "where": "\"orca_teams\".\"status\" = 'active'"
+ },
+ "idx_orca_teams_status": {
+ "name": "idx_orca_teams_status",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "orca_teams_lead_session_id_sessions_id_fk": {
+ "name": "orca_teams_lead_session_id_sessions_id_fk",
+ "tableFrom": "orca_teams",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "lead_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "orca_worker_creation_reservations": {
+ "name": "orca_worker_creation_reservations",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_orca_worker_creation_reservations_team_label": {
+ "name": "uniq_orca_worker_creation_reservations_team_label",
+ "columns": [
+ "team_id",
+ "lower(\"label\")"
+ ],
+ "isUnique": true
+ },
+ "idx_orca_worker_creation_reservations_expires_at": {
+ "name": "idx_orca_worker_creation_reservations_expires_at",
+ "columns": [
+ "expires_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "orca_worker_creation_reservations_team_id_orca_teams_id_fk": {
+ "name": "orca_worker_creation_reservations_team_id_orca_teams_id_fk",
+ "tableFrom": "orca_worker_creation_reservations",
+ "tableTo": "orca_teams",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "orca_workers": {
+ "name": "orca_workers",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "team_id": {
+ "name": "team_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'idle'"
+ },
+ "label": {
+ "name": "label",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "worktree_branch": {
+ "name": "worktree_branch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "role": {
+ "name": "role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'developer'"
+ },
+ "focused": {
+ "name": "focused",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "idle_since": {
+ "name": "idle_since",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_orca_workers_session_id": {
+ "name": "uniq_orca_workers_session_id",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": true
+ },
+ "uniq_orca_workers_team_label": {
+ "name": "uniq_orca_workers_team_label",
+ "columns": [
+ "team_id",
+ "lower(\"label\")"
+ ],
+ "isUnique": true
+ },
+ "uniq_orca_workers_focused_per_team": {
+ "name": "uniq_orca_workers_focused_per_team",
+ "columns": [
+ "team_id"
+ ],
+ "isUnique": true,
+ "where": "\"orca_workers\".\"focused\" = true"
+ },
+ "idx_orca_workers_team_id": {
+ "name": "idx_orca_workers_team_id",
+ "columns": [
+ "team_id"
+ ],
+ "isUnique": false
+ },
+ "idx_orca_workers_status": {
+ "name": "idx_orca_workers_status",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "orca_workers_team_id_orca_teams_id_fk": {
+ "name": "orca_workers_team_id_orca_teams_id_fk",
+ "tableFrom": "orca_workers",
+ "tableTo": "orca_teams",
+ "columnsFrom": [
+ "team_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "orca_workers_session_id_sessions_id_fk": {
+ "name": "orca_workers_session_id_sessions_id_fk",
+ "tableFrom": "orca_workers",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "project_aliases": {
+ "name": "project_aliases",
+ "columns": {
+ "project_key": {
+ "name": "project_key",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "alias": {
+ "name": "alias",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_project_aliases_updated_at": {
+ "name": "idx_project_aliases_updated_at",
+ "columns": [
+ "updated_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "project_automation_consents": {
+ "name": "project_automation_consents",
+ "columns": {
+ "working_dir": {
+ "name": "working_dir",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "consented_at": {
+ "name": "consented_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "config_hash": {
+ "name": "config_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "recent_workdirs": {
+ "name": "recent_workdirs",
+ "columns": {
+ "path": {
+ "name": "path",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_used_at": {
+ "name": "last_used_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_recent_workdirs_last_used_at": {
+ "name": "idx_recent_workdirs_last_used_at",
+ "columns": [
+ "last_used_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "right_sidebar_tabs": {
+ "name": "right_sidebar_tabs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "position": {
+ "name": "position",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "state": {
+ "name": "state",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "right_sidebar_tabs_session_idx": {
+ "name": "right_sidebar_tabs_session_idx",
+ "columns": [
+ "session_id",
+ "position"
+ ],
+ "isUnique": false
+ },
+ "right_sidebar_tabs_subagents_singleton_idx": {
+ "name": "right_sidebar_tabs_subagents_singleton_idx",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": true,
+ "where": "\"right_sidebar_tabs\".\"kind\" = 'subagents'"
+ },
+ "right_sidebar_tabs_bot_artifacts_singleton_idx": {
+ "name": "right_sidebar_tabs_bot_artifacts_singleton_idx",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": true,
+ "where": "\"right_sidebar_tabs\".\"kind\" = 'bot-artifacts'"
+ }
+ },
+ "foreignKeys": {
+ "right_sidebar_tabs_session_id_sessions_id_fk": {
+ "name": "right_sidebar_tabs_session_id_sessions_id_fk",
+ "tableFrom": "right_sidebar_tabs",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "schedule_runs": {
+ "name": "schedule_runs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "schedule_id": {
+ "name": "schedule_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "fired_at": {
+ "name": "fired_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "finished_at": {
+ "name": "finished_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "error_msg": {
+ "name": "error_msg",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "cost_usd": {
+ "name": "cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "estimated_value_usd": {
+ "name": "estimated_value_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_amount": {
+ "name": "cost_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "estimated_value_amount": {
+ "name": "estimated_value_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "cost_currency": {
+ "name": "cost_currency",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "cost_is_approximate": {
+ "name": "cost_is_approximate",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "cost_attribution": {
+ "name": "cost_attribution",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'legacy'"
+ },
+ "result_text": {
+ "name": "result_text",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "pre_run_hook_result": {
+ "name": "pre_run_hook_result",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "read_at": {
+ "name": "read_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "heartbeat_at": {
+ "name": "heartbeat_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_schedule_runs_schedule": {
+ "name": "idx_schedule_runs_schedule",
+ "columns": [
+ "schedule_id",
+ "fired_at"
+ ],
+ "isUnique": false
+ },
+ "idx_schedule_runs_running_schedule": {
+ "name": "idx_schedule_runs_running_schedule",
+ "columns": [
+ "schedule_id"
+ ],
+ "isUnique": false,
+ "where": "\"schedule_runs\".\"status\" = 'running'"
+ },
+ "idx_schedule_runs_running_heartbeat": {
+ "name": "idx_schedule_runs_running_heartbeat",
+ "columns": [
+ "heartbeat_at"
+ ],
+ "isUnique": false,
+ "where": "\"schedule_runs\".\"status\" = 'running' AND \"schedule_runs\".\"heartbeat_at\" IS NOT NULL"
+ },
+ "idx_schedule_runs_running_legacy": {
+ "name": "idx_schedule_runs_running_legacy",
+ "columns": [
+ "fired_at"
+ ],
+ "isUnique": false,
+ "where": "\"schedule_runs\".\"status\" = 'running' AND \"schedule_runs\".\"heartbeat_at\" IS NULL"
+ },
+ "idx_schedule_runs_unread_terminal": {
+ "name": "idx_schedule_runs_unread_terminal",
+ "columns": [
+ "schedule_id",
+ "status",
+ "fired_at"
+ ],
+ "isUnique": false,
+ "where": "\"schedule_runs\".\"read_at\" IS NULL AND \"schedule_runs\".\"status\" IN ('success', 'failed', 'aborted', 'interrupted')"
+ },
+ "idx_schedule_runs_session_latest": {
+ "name": "idx_schedule_runs_session_latest",
+ "columns": [
+ "session_id",
+ "fired_at",
+ "id"
+ ],
+ "isUnique": false,
+ "where": "\"schedule_runs\".\"session_id\" IS NOT NULL"
+ }
+ },
+ "foreignKeys": {
+ "schedule_runs_schedule_id_schedules_id_fk": {
+ "name": "schedule_runs_schedule_id_schedules_id_fk",
+ "tableFrom": "schedule_runs",
+ "tableTo": "schedules",
+ "columnsFrom": [
+ "schedule_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "schedule_runs_session_id_sessions_id_fk": {
+ "name": "schedule_runs_session_id_sessions_id_fk",
+ "tableFrom": "schedule_runs",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "schedule_session_latest_runs": {
+ "name": "schedule_session_latest_runs",
+ "columns": {
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "run_id": {
+ "name": "run_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "fired_at": {
+ "name": "fired_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_schedule_session_latest_runs_run": {
+ "name": "idx_schedule_session_latest_runs_run",
+ "columns": [
+ "run_id"
+ ],
+ "isUnique": true
+ }
+ },
+ "foreignKeys": {
+ "schedule_session_latest_runs_session_id_sessions_id_fk": {
+ "name": "schedule_session_latest_runs_session_id_sessions_id_fk",
+ "tableFrom": "schedule_session_latest_runs",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "schedule_session_latest_runs_run_id_schedule_runs_id_fk": {
+ "name": "schedule_session_latest_runs_run_id_schedule_runs_id_fk",
+ "tableFrom": "schedule_session_latest_runs",
+ "tableTo": "schedule_runs",
+ "columnsFrom": [
+ "run_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "schedules": {
+ "name": "schedules",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "name": {
+ "name": "name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "prompt": {
+ "name": "prompt",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "job_type": {
+ "name": "job_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'prompt'"
+ },
+ "job_config": {
+ "name": "job_config",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "execution_mode": {
+ "name": "execution_mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'agent'"
+ },
+ "script_config": {
+ "name": "script_config",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false,
+ "default": "'user'"
+ },
+ "project_config_id": {
+ "name": "project_config_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "legacy_session_fallback": {
+ "name": "legacy_session_fallback",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'cron'"
+ },
+ "cron_expr": {
+ "name": "cron_expr",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "timezone": {
+ "name": "timezone",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "recurring": {
+ "name": "recurring",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "manual": {
+ "name": "manual",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "interval_ms": {
+ "name": "interval_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "model_agent_kind": {
+ "name": "model_agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "effort": {
+ "name": "effort",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "fast_mode": {
+ "name": "fast_mode",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "working_dir": {
+ "name": "working_dir",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "workspace_kind": {
+ "name": "workspace_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'project'"
+ },
+ "use_worktree": {
+ "name": "use_worktree",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "target_session_id": {
+ "name": "target_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "persistent_session": {
+ "name": "persistent_session",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "silent_when_idle": {
+ "name": "silent_when_idle",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "pre_run_hook_command": {
+ "name": "pre_run_hook_command",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "pre_run_hook_timeout_ms": {
+ "name": "pre_run_hook_timeout_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "skip_log_session_id": {
+ "name": "skip_log_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "notify_desktop": {
+ "name": "notify_desktop",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": true
+ },
+ "notify_feishu": {
+ "name": "notify_feishu",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "notify_wecom_group": {
+ "name": "notify_wecom_group",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_fired_at": {
+ "name": "last_fired_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_finished_at": {
+ "name": "last_finished_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "next_fire_at": {
+ "name": "next_fire_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "expire_at": {
+ "name": "expire_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_schedules_active_next": {
+ "name": "idx_schedules_active_next",
+ "columns": [
+ "status",
+ "next_fire_at"
+ ],
+ "isUnique": false
+ },
+ "idx_schedules_target_session": {
+ "name": "idx_schedules_target_session",
+ "columns": [
+ "target_session_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "schedules_target_session_id_sessions_id_fk": {
+ "name": "schedules_target_session_id_sessions_id_fk",
+ "tableFrom": "schedules",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "target_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ },
+ "schedules_skip_log_session_id_sessions_id_fk": {
+ "name": "schedules_skip_log_session_id_sessions_id_fk",
+ "tableFrom": "schedules",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "skip_log_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "session_goals": {
+ "name": "session_goals",
+ "columns": {
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "objective": {
+ "name": "objective",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "budget_tokens": {
+ "name": "budget_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "max_turns": {
+ "name": "max_turns",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "no_progress_limit": {
+ "name": "no_progress_limit",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "turns_used": {
+ "name": "turns_used",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "tokens_used": {
+ "name": "tokens_used",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "no_progress_streak": {
+ "name": "no_progress_streak",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "usage_reset_at": {
+ "name": "usage_reset_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_reason": {
+ "name": "last_reason",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "started_at": {
+ "name": "started_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_session_goals_status": {
+ "name": "idx_session_goals_status",
+ "columns": [
+ "status"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "session_goals_session_id_sessions_id_fk": {
+ "name": "session_goals_session_id_sessions_id_fk",
+ "tableFrom": "session_goals",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "session_pr_refs": {
+ "name": "session_pr_refs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "owner": {
+ "name": "owner",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "repo": {
+ "name": "repo",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "pr_number": {
+ "name": "pr_number",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "url": {
+ "name": "url",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "first_seen_at": {
+ "name": "first_seen_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "last_seen_at": {
+ "name": "last_seen_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_session_pr_refs": {
+ "name": "uniq_session_pr_refs",
+ "columns": [
+ "session_id",
+ "owner",
+ "repo",
+ "pr_number"
+ ],
+ "isUnique": true
+ },
+ "idx_session_pr_refs_session_last_seen": {
+ "name": "idx_session_pr_refs_session_last_seen",
+ "columns": [
+ "session_id",
+ "last_seen_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "session_pr_refs_session_id_sessions_id_fk": {
+ "name": "session_pr_refs_session_id_sessions_id_fk",
+ "tableFrom": "session_pr_refs",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "sessions": {
+ "name": "sessions",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'New Maker'"
+ },
+ "working_dir": {
+ "name": "working_dir",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "workspace_kind": {
+ "name": "workspace_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'project'"
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'claude-sonnet-4-6'"
+ },
+ "effort": {
+ "name": "effort",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'high'"
+ },
+ "permission_mode": {
+ "name": "permission_mode",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'ask'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'active'"
+ },
+ "sdk_session_id": {
+ "name": "sdk_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "total_token_usage": {
+ "name": "total_token_usage",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_cost_usd": {
+ "name": "total_cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_cost_amount": {
+ "name": "total_cost_amount",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "total_cost_currency": {
+ "name": "total_cost_currency",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "total_cost_is_approximate": {
+ "name": "total_cost_is_approximate",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "context_tokens": {
+ "name": "context_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "context_window": {
+ "name": "context_window",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "context_window_runtime": {
+ "name": "context_window_runtime",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "fast_mode": {
+ "name": "fast_mode",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "plan_mode_enabled": {
+ "name": "plan_mode_enabled",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "cleared_at": {
+ "name": "cleared_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "pinned_at": {
+ "name": "pinned_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "summary": {
+ "name": "summary",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "provider_id": {
+ "name": "provider_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "user_send_at": {
+ "name": "user_send_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'cc'"
+ },
+ "orca_role": {
+ "name": "orca_role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "parent_session_id": {
+ "name": "parent_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "forked_at_message_id": {
+ "name": "forked_at_message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "worktree_path": {
+ "name": "worktree_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'desktop'"
+ },
+ "feishu_open_id": {
+ "name": "feishu_open_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "feishu_bot_app_id": {
+ "name": "feishu_bot_app_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "im_bot_context_id": {
+ "name": "im_bot_context_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "im_user_id": {
+ "name": "im_user_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "used_project_context": {
+ "name": "used_project_context",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "codex_history_has_product_prompt": {
+ "name": "codex_history_has_product_prompt",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "codex_plan_json": {
+ "name": "codex_plan_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "extra_dirs": {
+ "name": "extra_dirs",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "writable_dirs": {
+ "name": "writable_dirs",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "remote_host_id": {
+ "name": "remote_host_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "active_turn_started_at": {
+ "name": "active_turn_started_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "active_turn_pid": {
+ "name": "active_turn_pid",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_turn_ended_at": {
+ "name": "last_turn_ended_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "list_preview": {
+ "name": "list_preview",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "list_preview_role": {
+ "name": "list_preview_role",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "list_message_count": {
+ "name": "list_message_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_sessions_updated_at": {
+ "name": "idx_sessions_updated_at",
+ "columns": [
+ "updated_at"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_user_send_at": {
+ "name": "idx_sessions_user_send_at",
+ "columns": [
+ "user_send_at"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_sdk_session_id": {
+ "name": "idx_sessions_sdk_session_id",
+ "columns": [
+ "sdk_session_id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_workdir_created": {
+ "name": "idx_sessions_workdir_created",
+ "columns": [
+ "working_dir",
+ "created_at",
+ "id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_created_at": {
+ "name": "idx_sessions_created_at",
+ "columns": [
+ "created_at",
+ "id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_workspace_kind": {
+ "name": "idx_sessions_workspace_kind",
+ "columns": [
+ "workspace_kind"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_parent_session_id": {
+ "name": "idx_sessions_parent_session_id",
+ "columns": [
+ "parent_session_id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_orca_role": {
+ "name": "idx_sessions_orca_role",
+ "columns": [
+ "orca_role"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_worktree_path": {
+ "name": "idx_sessions_worktree_path",
+ "columns": [
+ "worktree_path"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_feishu_lookup": {
+ "name": "idx_sessions_feishu_lookup",
+ "columns": [
+ "source",
+ "feishu_bot_app_id",
+ "feishu_open_id"
+ ],
+ "isUnique": false
+ },
+ "idx_sessions_im_lookup": {
+ "name": "idx_sessions_im_lookup",
+ "columns": [
+ "source",
+ "im_bot_context_id",
+ "im_user_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "sessions_parent_session_id_sessions_id_fk": {
+ "name": "sessions_parent_session_id_sessions_id_fk",
+ "tableFrom": "sessions",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "parent_session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "skill_usage_exposures": {
+ "name": "skill_usage_exposures",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "analyzer_version": {
+ "name": "analyzer_version",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'6'"
+ },
+ "raw_file_path": {
+ "name": "raw_file_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "raw_line_no": {
+ "name": "raw_line_no",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sdk_session_id": {
+ "name": "sdk_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "skill_name": {
+ "name": "skill_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "skill_path": {
+ "name": "skill_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "skill_document_hash": {
+ "name": "skill_document_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "exposure_content_hash": {
+ "name": "exposure_content_hash",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "document_hash_source": {
+ "name": "document_hash_source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tool_use_id": {
+ "name": "tool_use_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "seen_at": {
+ "name": "seen_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "tool_call_count": {
+ "name": "tool_call_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "repeated_tool_call_count": {
+ "name": "repeated_tool_call_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "tool_error_count": {
+ "name": "tool_error_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "command_call_count": {
+ "name": "command_call_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "command_failure_count": {
+ "name": "command_failure_count",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ }
+ },
+ "indexes": {
+ "idx_skill_usage_exposures_skill_document_version": {
+ "name": "idx_skill_usage_exposures_skill_document_version",
+ "columns": [
+ "analyzer_version",
+ "skill_name",
+ "skill_document_hash"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_skill_recent": {
+ "name": "idx_skill_usage_exposures_skill_recent",
+ "columns": [
+ "skill_name",
+ "analyzer_version",
+ "seen_at"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_skill_recent_any_version": {
+ "name": "idx_skill_usage_exposures_skill_recent_any_version",
+ "columns": [
+ "skill_name",
+ "seen_at"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_analyzer_recent_source": {
+ "name": "idx_skill_usage_exposures_analyzer_recent_source",
+ "columns": [
+ "analyzer_version",
+ "seen_at",
+ "raw_file_path"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_session": {
+ "name": "idx_skill_usage_exposures_session",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_exposures_raw_file": {
+ "name": "idx_skill_usage_exposures_raw_file",
+ "columns": [
+ "raw_file_path"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "skill_usage_exposures_raw_file_path_skill_usage_sources_raw_file_path_fk": {
+ "name": "skill_usage_exposures_raw_file_path_skill_usage_sources_raw_file_path_fk",
+ "tableFrom": "skill_usage_exposures",
+ "tableTo": "skill_usage_sources",
+ "columnsFrom": [
+ "raw_file_path"
+ ],
+ "columnsTo": [
+ "raw_file_path"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "skill_usage_sources": {
+ "name": "skill_usage_sources",
+ "columns": {
+ "raw_file_path": {
+ "name": "raw_file_path",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "analyzer_version": {
+ "name": "analyzer_version",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'6'"
+ },
+ "agent_kind": {
+ "name": "agent_kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "sdk_session_id": {
+ "name": "sdk_session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mtime_ms": {
+ "name": "mtime_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "size_bytes": {
+ "name": "size_bytes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "last_scanned_at": {
+ "name": "last_scanned_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'ok'"
+ },
+ "error": {
+ "name": "error",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_skill_usage_sources_session": {
+ "name": "idx_skill_usage_sources_session",
+ "columns": [
+ "session_id"
+ ],
+ "isUnique": false
+ },
+ "idx_skill_usage_sources_sdk_session": {
+ "name": "idx_skill_usage_sources_sdk_session",
+ "columns": [
+ "sdk_session_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "subagent_run_aliases": {
+ "name": "subagent_run_aliases",
+ "columns": {
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "alias": {
+ "name": "alias",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "run_id": {
+ "name": "run_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "subagent_run_aliases_lookup_idx": {
+ "name": "subagent_run_aliases_lookup_idx",
+ "columns": [
+ "session_id",
+ "provider",
+ "alias",
+ "created_at"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "subagent_run_aliases_session_id_sessions_id_fk": {
+ "name": "subagent_run_aliases_session_id_sessions_id_fk",
+ "tableFrom": "subagent_run_aliases",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "subagent_run_aliases_run_id_subagent_runs_id_fk": {
+ "name": "subagent_run_aliases_run_id_subagent_runs_id_fk",
+ "tableFrom": "subagent_run_aliases",
+ "tableTo": "subagent_runs",
+ "columnsFrom": [
+ "run_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {
+ "subagent_run_aliases_run_id_alias_pk": {
+ "columns": [
+ "run_id",
+ "alias"
+ ],
+ "name": "subagent_run_aliases_run_id_alias_pk"
+ }
+ },
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "subagent_runs": {
+ "name": "subagent_runs",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "provider": {
+ "name": "provider",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "logical_agent_id": {
+ "name": "logical_agent_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "parent_tool_use_id": {
+ "name": "parent_tool_use_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "aliases": {
+ "name": "aliases",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "provider_run_ids": {
+ "name": "provider_run_ids",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'running'"
+ },
+ "title": {
+ "name": "title",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "description": {
+ "name": "description",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "summary": {
+ "name": "summary",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "returned_result": {
+ "name": "returned_result",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "returned_result_empty": {
+ "name": "returned_result_empty",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "returned_result_truncated": {
+ "name": "returned_result_truncated",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "model": {
+ "name": "model",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "reasoning_effort": {
+ "name": "reasoning_effort",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "total_tokens": {
+ "name": "total_tokens",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "tool_uses": {
+ "name": "tool_uses",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "duration_ms": {
+ "name": "duration_ms",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "cost_usd": {
+ "name": "cost_usd",
+ "type": "real",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "capabilities": {
+ "name": "capabilities",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'{}'"
+ },
+ "activity": {
+ "name": "activity",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "started_at": {
+ "name": "started_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "ended_at": {
+ "name": "ended_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "rewind_at": {
+ "name": "rewind_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "deleted_at": {
+ "name": "deleted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "subagent_runs_logical_idx": {
+ "name": "subagent_runs_logical_idx",
+ "columns": [
+ "session_id",
+ "provider",
+ "logical_agent_id"
+ ],
+ "isUnique": false
+ },
+ "subagent_runs_session_idx": {
+ "name": "subagent_runs_session_idx",
+ "columns": [
+ "session_id",
+ "rewind_at",
+ "deleted_at",
+ "started_at"
+ ],
+ "isUnique": false
+ },
+ "subagent_runs_parent_tool_use_idx": {
+ "name": "subagent_runs_parent_tool_use_idx",
+ "columns": [
+ "session_id",
+ "parent_tool_use_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "subagent_runs_session_id_sessions_id_fk": {
+ "name": "subagent_runs_session_id_sessions_id_fk",
+ "tableFrom": "subagent_runs",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "vec_table_meta": {
+ "name": "vec_table_meta",
+ "columns": {
+ "vec_table": {
+ "name": "vec_table",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "source": {
+ "name": "source",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "model_id": {
+ "name": "model_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "dim": {
+ "name": "dim",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "registered_at": {
+ "name": "registered_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "notes": {
+ "name": "notes",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {},
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "wechat_file_attachments": {
+ "name": "wechat_file_attachments",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "binding_epoch": {
+ "name": "binding_epoch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "abs_path": {
+ "name": "abs_path",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "original_name": {
+ "name": "original_name",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "mime_type": {
+ "name": "mime_type",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "bytes": {
+ "name": "bytes",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'staged'"
+ },
+ "promoted_at": {
+ "name": "promoted_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "idx_wechat_file_attachments_task": {
+ "name": "idx_wechat_file_attachments_task",
+ "columns": [
+ "binding_epoch",
+ "task_id"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "wechat_file_attachments_binding_epoch_wechat_sync_state_binding_epoch_fk": {
+ "name": "wechat_file_attachments_binding_epoch_wechat_sync_state_binding_epoch_fk",
+ "tableFrom": "wechat_file_attachments",
+ "tableTo": "wechat_sync_state",
+ "columnsFrom": [
+ "binding_epoch"
+ ],
+ "columnsTo": [
+ "binding_epoch"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "wechat_file_attachments_task_id_wechat_inbox_id_fk": {
+ "name": "wechat_file_attachments_task_id_wechat_inbox_id_fk",
+ "tableFrom": "wechat_file_attachments",
+ "tableTo": "wechat_inbox",
+ "columnsFrom": [
+ "task_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "wechat_file_attachments_session_id_sessions_id_fk": {
+ "name": "wechat_file_attachments_session_id_sessions_id_fk",
+ "tableFrom": "wechat_file_attachments",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "wechat_inbox": {
+ "name": "wechat_inbox",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "binding_epoch": {
+ "name": "binding_epoch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "platform_message_id": {
+ "name": "platform_message_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "platform_seq": {
+ "name": "platform_seq",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "peer_id": {
+ "name": "peer_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "received_at": {
+ "name": "received_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "platform_created_at": {
+ "name": "platform_created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "expires_at": {
+ "name": "expires_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "lease_until": {
+ "name": "lease_until",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "session_id": {
+ "name": "session_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "conversation_epoch": {
+ "name": "conversation_epoch",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "payload_json": {
+ "name": "payload_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "context_nonce": {
+ "name": "context_nonce",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "context_ciphertext": {
+ "name": "context_ciphertext",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "context_tag": {
+ "name": "context_tag",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "last_error_code": {
+ "name": "last_error_code",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_wechat_inbox_platform_message": {
+ "name": "uniq_wechat_inbox_platform_message",
+ "columns": [
+ "binding_epoch",
+ "platform_message_id"
+ ],
+ "isUnique": true
+ },
+ "idx_wechat_inbox_queue": {
+ "name": "idx_wechat_inbox_queue",
+ "columns": [
+ "binding_epoch",
+ "status",
+ "received_at"
+ ],
+ "isUnique": false
+ },
+ "idx_wechat_inbox_lease": {
+ "name": "idx_wechat_inbox_lease",
+ "columns": [
+ "binding_epoch",
+ "lease_until"
+ ],
+ "isUnique": false
+ },
+ "idx_wechat_inbox_conversation": {
+ "name": "idx_wechat_inbox_conversation",
+ "columns": [
+ "binding_epoch",
+ "peer_id",
+ "conversation_epoch"
+ ],
+ "isUnique": false
+ },
+ "uniq_wechat_inbox_running_session": {
+ "name": "uniq_wechat_inbox_running_session",
+ "columns": [
+ "binding_epoch",
+ "session_id"
+ ],
+ "isUnique": true,
+ "where": "\"wechat_inbox\".\"session_id\" IS NOT NULL AND \"wechat_inbox\".\"status\" IN ('dispatching', 'accepted_running', 'waiting_desktop', 'delivery_pending')"
+ }
+ },
+ "foreignKeys": {
+ "wechat_inbox_binding_epoch_wechat_sync_state_binding_epoch_fk": {
+ "name": "wechat_inbox_binding_epoch_wechat_sync_state_binding_epoch_fk",
+ "tableFrom": "wechat_inbox",
+ "tableTo": "wechat_sync_state",
+ "columnsFrom": [
+ "binding_epoch"
+ ],
+ "columnsTo": [
+ "binding_epoch"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "wechat_inbox_session_id_sessions_id_fk": {
+ "name": "wechat_inbox_session_id_sessions_id_fk",
+ "tableFrom": "wechat_inbox",
+ "tableTo": "sessions",
+ "columnsFrom": [
+ "session_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "set null",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "wechat_outbox": {
+ "name": "wechat_outbox",
+ "columns": {
+ "id": {
+ "name": "id",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "binding_epoch": {
+ "name": "binding_epoch",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "task_id": {
+ "name": "task_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "client_id": {
+ "name": "client_id",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "kind": {
+ "name": "kind",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "chunk_index": {
+ "name": "chunk_index",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "text": {
+ "name": "text",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "media_json": {
+ "name": "media_json",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'[]'"
+ },
+ "status": {
+ "name": "status",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "'pending'"
+ },
+ "attempts": {
+ "name": "attempts",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": 0
+ },
+ "next_retry_at": {
+ "name": "next_retry_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "created_at": {
+ "name": "created_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "delivered_at": {
+ "name": "delivered_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_wechat_outbox_client_id": {
+ "name": "uniq_wechat_outbox_client_id",
+ "columns": [
+ "binding_epoch",
+ "client_id"
+ ],
+ "isUnique": true
+ },
+ "idx_wechat_outbox_delivery": {
+ "name": "idx_wechat_outbox_delivery",
+ "columns": [
+ "binding_epoch",
+ "status",
+ "next_retry_at"
+ ],
+ "isUnique": false
+ },
+ "idx_wechat_outbox_task": {
+ "name": "idx_wechat_outbox_task",
+ "columns": [
+ "binding_epoch",
+ "task_id",
+ "chunk_index"
+ ],
+ "isUnique": false
+ }
+ },
+ "foreignKeys": {
+ "wechat_outbox_binding_epoch_wechat_sync_state_binding_epoch_fk": {
+ "name": "wechat_outbox_binding_epoch_wechat_sync_state_binding_epoch_fk",
+ "tableFrom": "wechat_outbox",
+ "tableTo": "wechat_sync_state",
+ "columnsFrom": [
+ "binding_epoch"
+ ],
+ "columnsTo": [
+ "binding_epoch"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ },
+ "wechat_outbox_task_id_wechat_inbox_id_fk": {
+ "name": "wechat_outbox_task_id_wechat_inbox_id_fk",
+ "tableFrom": "wechat_outbox",
+ "tableTo": "wechat_inbox",
+ "columnsFrom": [
+ "task_id"
+ ],
+ "columnsTo": [
+ "id"
+ ],
+ "onDelete": "cascade",
+ "onUpdate": "no action"
+ }
+ },
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ },
+ "wechat_sync_state": {
+ "name": "wechat_sync_state",
+ "columns": {
+ "binding_epoch": {
+ "name": "binding_epoch",
+ "type": "text",
+ "primaryKey": true,
+ "notNull": true,
+ "autoincrement": false
+ },
+ "is_active": {
+ "name": "is_active",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": false
+ },
+ "sync_cursor": {
+ "name": "sync_cursor",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false,
+ "default": "''"
+ },
+ "last_poll_at": {
+ "name": "last_poll_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "last_error_code": {
+ "name": "last_error_code",
+ "type": "text",
+ "primaryKey": false,
+ "notNull": false,
+ "autoincrement": false
+ },
+ "updated_at": {
+ "name": "updated_at",
+ "type": "integer",
+ "primaryKey": false,
+ "notNull": true,
+ "autoincrement": false
+ }
+ },
+ "indexes": {
+ "uniq_wechat_sync_active": {
+ "name": "uniq_wechat_sync_active",
+ "columns": [
+ "is_active"
+ ],
+ "isUnique": true,
+ "where": "\"wechat_sync_state\".\"is_active\" = 1"
+ }
+ },
+ "foreignKeys": {},
+ "compositePrimaryKeys": {},
+ "uniqueConstraints": {},
+ "checkConstraints": {}
+ }
+ },
+ "views": {},
+ "enums": {},
+ "_meta": {
+ "schemas": {},
+ "tables": {},
+ "columns": {}
+ },
+ "internal": {
+ "indexes": {
+ "uniq_orca_worker_creation_reservations_team_label": {
+ "columns": {
+ "lower(\"label\")": {
+ "isExpression": true
+ }
+ }
+ },
+ "uniq_orca_workers_team_label": {
+ "columns": {
+ "lower(\"label\")": {
+ "isExpression": true
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/desktop/drizzle/meta/_journal.json b/apps/desktop/drizzle/meta/_journal.json
index 5c4f387887..bec3564d7d 100644
--- a/apps/desktop/drizzle/meta/_journal.json
+++ b/apps/desktop/drizzle/meta/_journal.json
@@ -750,6 +750,13 @@
"when": 1789194577226,
"tag": "0106_retain_all_recent_workdirs",
"breakpoints": true
+ },
+ {
+ "idx": 107,
+ "version": "6",
+ "when": 1789354447826,
+ "tag": "0107_sudden_ultron",
+ "breakpoints": true
}
]
}
\ No newline at end of file
diff --git a/apps/desktop/src/main/im/feishu/__tests__/notificationOrigin.test.ts b/apps/desktop/src/main/im/feishu/__tests__/notificationOrigin.test.ts
new file mode 100644
index 0000000000..ecec4ac657
--- /dev/null
+++ b/apps/desktop/src/main/im/feishu/__tests__/notificationOrigin.test.ts
@@ -0,0 +1,151 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import type { FeishuIM, IMMessageEvent } from '@cindy/im';
+
+const mocks = vi.hoisted(() => ({
+ values: vi.fn(), origin: null as null | { sessionId: string },
+ session: { workingDir: '/tmp/task', status: 'active' } as Record<string, unknown>,
+ where: vi.fn(),
+}));
+vi.mock('../../../logger', () => ({ createLogger: () => ({ info: vi.fn(), error: vi.fn() }) }));
+vi.mock('drizzle-orm', () => ({
+ eq: (column: unknown, value: unknown) => [column, value],
+ and: (...conditions: unknown[]) => conditions,
+}));
+vi.mock('../../../localDb/schema', () => ({
+ imNotificationOrigins: { channel: 'channel', botContextId: 'bot', userId: 'user', messageId: 'message', chatId: 'chat' },
+ sessions: { id: 'session' },
+}));
+vi.mock('../../../localDb/client/current', () => ({
+ getDbClient: () => ({ drizzle: {
+ insert: () => ({ values: mocks.values }),
+ select: () => ({ from: (table: { id?: string }) => ({ where: (condition: unknown) => {
+ mocks.where(condition);
+ return { limit: async () => table.id ? [mocks.session] : mocks.origin ? [mocks.origin] : [] };
+ } }) }),
+ } }),
+}));
+import { activateImAccountBoundary, deactivateImAccountBoundary } from '../../accountBoundary';
+import { resolveFeishuNotificationReply, sendFeishuSessionNotification } from '../notificationOrigin';
+
+const sendNotification = vi.fn();
+const im = {
+ getStatus: () => ({ kind: 'connected', appId: 'cli_bot' }),
+ getOwnerOpenId: () => 'ou_owner', sendNotification,
+} as unknown as FeishuIM;
+const event = {
+ senderId: 'ou_owner', contextId: 'cli_bot', chatId: 'oc_chat',
+ replyThread: { rootMessageId: 'om_root', threadId: 'omt_topic' },
+} as IMMessageEvent;
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ activateImAccountBoundary();
+ mocks.origin = { sessionId: 'original' };
+ mocks.session = { workingDir: '/tmp/task', status: 'active' };
+ mocks.values.mockResolvedValue(undefined);
+ sendNotification.mockResolvedValue({ messageId: 'om_root', chatId: 'oc_chat' });
+});
+
+describe('Feishu notification origins', () => {
+ it('stores the provider receipt and resolves the original session by bot, owner, chat and root', async () => {
+ await expect(sendFeishuSessionNotification(im, 'original', 'done')).resolves.toEqual({
+ messageId: 'om_root', chatId: 'oc_chat', sessionLinked: true,
+ });
+ expect(mocks.values).toHaveBeenCalledWith(expect.objectContaining({
+ botContextId: 'cli_bot', userId: 'ou_owner', chatId: 'oc_chat', messageId: 'om_root', sessionId: 'original',
+ }));
+ await expect(resolveFeishuNotificationReply(im, event)).resolves.toBe('original');
+ expect(mocks.where).toHaveBeenCalledWith([
+ ['channel', 'feishu'], ['bot', 'cli_bot'], ['user', 'ou_owner'], ['message', 'om_root'], ['chat', 'oc_chat'],
+ ]);
+ });
+
+ it('waits for an in-flight receipt before looking up a fast reply', async () => {
+ let release!: (value: { messageId: string; chatId: string }) => void;
+ sendNotification.mockImplementationOnce(() => new Promise((resolve) => { release = resolve; }));
+ mocks.origin = null;
+ const send = sendFeishuSessionNotification(im, 'original', 'done');
+ await Promise.resolve();
+ const reply = resolveFeishuNotificationReply(im, event);
+ await vi.waitFor(() => expect(mocks.where).toHaveBeenCalledTimes(1));
+ mocks.origin = { sessionId: 'original' };
+ release({ messageId: 'om_root', chatId: 'oc_chat' });
+ await send;
+ await expect(reply).resolves.toBe('original');
+ });
+
+ it('ignores another owner or bot and an unlinked legacy notification', async () => {
+ await expect(resolveFeishuNotificationReply(im, { ...event, senderId: 'ou_other' })).resolves.toBeNull();
+ await expect(resolveFeishuNotificationReply(im, { ...event, contextId: 'cli_other' })).resolves.toBeNull();
+ expect(mocks.where).not.toHaveBeenCalled();
+ mocks.origin = null;
+ await expect(resolveFeishuNotificationReply(im, event)).resolves.toBeNull();
+ });
+
+ it('rejects a deleted original without treating its notification as unlinked', async () => {
+ mocks.session = { workingDir: '/tmp/task', status: 'deleted' };
+ await expect(resolveFeishuNotificationReply(im, event)).rejects.toThrow('unavailable');
+ });
+
+ it('does not persist a receipt into a replaced account', async () => {
+ sendNotification.mockImplementationOnce(async () => {
+ deactivateImAccountBoundary();
+ return { messageId: 'om_root', chatId: 'oc_chat' };
+ });
+ await expect(sendFeishuSessionNotification(im, 'original', 'done')).resolves.toEqual({
+ messageId: 'om_root', chatId: 'oc_chat', sessionLinked: false,
+ });
+ expect(mocks.values).not.toHaveBeenCalled();
+ });
+
+ it('returns the delivered receipt when persistence fails, without resending', async () => {
+ mocks.values.mockRejectedValueOnce(new Error('SQLITE_FULL'));
+ await expect(sendFeishuSessionNotification(im, 'original', 'done')).resolves.toEqual({
+ messageId: 'om_root', chatId: 'oc_chat', sessionLinked: false,
+ });
+ expect(sendNotification).toHaveBeenCalledTimes(1);
+ expect(mocks.values).toHaveBeenCalledTimes(1);
+ });
+
+ it('returns the delivered receipt even if its chat id is absent', async () => {
+ sendNotification.mockResolvedValueOnce({ messageId: 'om_root' });
+ await expect(sendFeishuSessionNotification(im, 'original', 'done')).resolves.toEqual({
+ messageId: 'om_root', sessionLinked: false,
+ });
+ expect(mocks.values).not.toHaveBeenCalled();
+ });
+
+ it('does not block an existing link on an unrelated send', async () => {
+ let finish!: (value: { messageId: string; chatId: string }) => void;
+ sendNotification.mockImplementationOnce(() => new Promise((resolve) => { finish = resolve; }));
+ const unrelated = sendFeishuSessionNotification(im, 'other', 'other');
+ try {
+ await expect(resolveFeishuNotificationReply(im, event)).resolves.toBe('original');
+ } finally {
+ finish({ messageId: 'om_other', chatId: 'oc_chat' });
+ await unrelated;
+ }
+ });
+
+ it('rechecks a fast reply as soon as its send finishes, even while another is pending', async () => {
+ let finishOther!: (value: { messageId: string; chatId: string }) => void;
+ let finishTarget!: (value: { messageId: string; chatId: string }) => void;
+ mocks.origin = null;
+ sendNotification.mockImplementationOnce(() => new Promise((resolve) => { finishOther = resolve; }));
+ sendNotification.mockImplementationOnce(() => new Promise((resolve) => { finishTarget = resolve; }));
+ const other = sendFeishuSessionNotification(im, 'other', 'other');
+ const target = sendFeishuSessionNotification(im, 'original', 'done');
+ const reply = resolveFeishuNotificationReply(im, event);
+ await vi.waitFor(() => expect(mocks.where).toHaveBeenCalledTimes(1));
+ mocks.origin = { sessionId: 'original' };
+ finishTarget({ messageId: 'om_root', chatId: 'oc_chat' });
+ try {
+ await target;
+ await expect(reply).resolves.toBe('original');
+ } finally {
+ finishOther({ messageId: 'om_other', chatId: 'oc_chat' });
+ await other;
+ }
+ });
+
+});
diff --git a/apps/desktop/src/main/im/feishu/adapter.ts b/apps/desktop/src/main/im/feishu/adapter.ts
index 5666b4402d..96ca924811 100644
--- a/apps/desktop/src/main/im/feishu/adapter.ts
+++ b/apps/desktop/src/main/im/feishu/adapter.ts
@@ -22,6 +22,7 @@ import { captureImContext } from '../../../shared/imMessageSource';
* (飞书有拉历史 API, 不需要 telegram 那样的本地群消息池)。
*/
+import { resolveFeishuNotificationReply } from './notificationOrigin';
import path from 'node:path';
import fs from 'node:fs';
import { app } from 'electron';
@@ -243,6 +244,11 @@ export function buildFeishuAdapter(
return {
channel: 'feishu',
messageSourceIm: () => feishuIm.getService(),
+ resolveNotificationReply: (event) => resolveFeishuNotificationReply(feishuIm, event),
+ notificationReplyText: {
+ unavailable: '暂时无法继续这条通知对应的任务,请在 Cindy 中确认任务仍可用后重试。',
+ commands: '本话题用于继续通知对应的任务。停止请用 !stop;其他命令请在主聊天中操作。',
+ },
im: feishuIm,
output: { kind: 'rich-card', im: feishuIm },
config,
diff --git a/apps/desktop/src/main/im/feishu/notificationOrigin.ts b/apps/desktop/src/main/im/feishu/notificationOrigin.ts
new file mode 100644
index 0000000000..895f4aab2e
--- /dev/null
+++ b/apps/desktop/src/main/im/feishu/notificationOrigin.ts
@@ -0,0 +1,123 @@
+/** Links private bot notification receipts to their original Cindy session, independently of /ctr. */
+import { and, eq } from 'drizzle-orm';
+import type { FeishuIM, IMMessageEvent } from '@cindy/im';
+import { getDbClient } from '../../localDb/client/current';
+import { imNotificationOrigins, sessions } from '../../localDb/schema';
+import { createLogger } from '../../logger';
+import {
+ captureImAccountGeneration,
+ isImAccountGenerationCurrent,
+ ImAccountScopeClosedError,
+ runInImAccountGeneration,
+} from '../accountBoundary';
+
+const log = createLogger('im:feishu:notification');
+const sending = new Map<string, Set<Promise<unknown>>>();
+
+function sendingKey(generation: number, appId: string, userId: string): string {
+ return JSON.stringify([generation, appId, userId]);
+}
+
+export function sendFeishuSessionNotification(
+ im: FeishuIM, sessionId: string, text: string,
+): Promise<{ messageId: string; chatId?: string; sessionLinked: boolean }> {
+ const generation = captureImAccountGeneration();
+ const status = im.getStatus();
+ const userId = im.getOwnerOpenId();
+ if (generation === null || status.kind !== 'connected' || !userId) {
+ return Promise.reject(new Error('Feishu notification channel is not ready'));
+ }
+ const db = getDbClient();
+ const key = sendingKey(generation, status.appId, userId);
+ const operation = runInImAccountGeneration(generation, async () => {
+ const current = im.getStatus();
+ if (current.kind !== 'connected' || current.appId !== status.appId || im.getOwnerOpenId() !== userId) {
+ throw new ImAccountScopeClosedError();
+ }
+ const receipt = await im.sendNotification(userId, text);
+ // A receipt proves delivery: subsequent failures must never become SEND_FAIL.
+ try {
+ if (!isImAccountGenerationCurrent(generation)) throw new ImAccountScopeClosedError();
+ if (!receipt.chatId) throw new Error('Notification receipt has no chat id');
+ await db.drizzle.insert(imNotificationOrigins).values({
+ channel: 'feishu',
+ botContextId: status.appId,
+ userId,
+ messageId: receipt.messageId,
+ chatId: receipt.chatId,
+ sessionId,
+ createdAt: Date.now(),
+ });
+ } catch {
+ log.error('notification sent but session link persistence failed', { message: receipt.messageId.slice(-8) });
+ return { ...receipt, sessionLinked: false };
+ }
+ log.info('notification linked', { message: receipt.messageId.slice(-8), session: sessionId.slice(-8) });
+ return { ...receipt, sessionLinked: true };
+ });
+ const pending = sending.get(key) ?? new Set<Promise<unknown>>();
+ sending.set(key, pending);
+ pending.add(operation);
+ const remove = () => {
+ pending.delete(operation);
+ if (!pending.size) sending.delete(key);
+ };
+ void operation.then(remove, remove);
+ return operation;
+}
+
+export async function resolveFeishuNotificationReply(im: FeishuIM, event: IMMessageEvent): Promise<string | null> {
+ if (!event.replyThread || event.speaker || event.senderId !== im.getOwnerOpenId()) return null;
+ const status = im.getStatus();
+ if (status.kind !== 'connected' || status.appId !== event.contextId) return null;
+ const generation = captureImAccountGeneration();
+ if (generation === null) throw new ImAccountScopeClosedError();
+ const db = getDbClient();
+ const readOrigin = async () => {
+ if (!isImAccountGenerationCurrent(generation)) throw new ImAccountScopeClosedError();
+ const [origin] = await db.drizzle.select({ sessionId: imNotificationOrigins.sessionId })
+ .from(imNotificationOrigins).where(and(
+ eq(imNotificationOrigins.channel, 'feishu'),
+ eq(imNotificationOrigins.botContextId, event.contextId),
+ eq(imNotificationOrigins.userId, event.senderId),
+ eq(imNotificationOrigins.messageId, event.replyThread!.rootMessageId),
+ eq(imNotificationOrigins.chatId, event.chatId),
+ )).limit(1);
+ if (!isImAccountGenerationCurrent(generation)) throw new ImAccountScopeClosedError();
+ return origin;
+ };
+ // Existing links must not wait for unrelated notifications. For a fast reply,
+ // recheck after each pending send settles, rather than waiting for every send.
+ const pending = new Set(sending.get(sendingKey(generation, status.appId, event.senderId)));
+ let origin = await readOrigin();
+ if (!origin && pending.size) {
+ const remaining = new Map([...pending].map((operation) => [
+ operation, operation.then(() => ({ operation }), () => ({ operation })),
+ ]));
+ let timer: ReturnType<typeof setTimeout> | undefined;
+ const timeout = new Promise<never>((_, reject) => {
+ timer = setTimeout(() => reject(new Error('Notification receipt is still pending')), 10_000);
+ });
+ try {
+ while (!origin && remaining.size) {
+ const { operation } = await Promise.race([...remaining.values(), timeout]);
+ remaining.delete(operation);
+ origin = await readOrigin();
+ }
+ } finally {
+ if (timer) clearTimeout(timer);
+ }
+ }
+ if (!origin) return null;
+ const [row] = await db.drizzle.select({ workingDir: sessions.workingDir, status: sessions.status, orcaRole: sessions.orcaRole }).from(sessions).where(eq(sessions.id, origin.sessionId)).limit(1);
+ if (!isImAccountGenerationCurrent(generation)) throw new ImAccountScopeClosedError();
+ const current = im.getStatus();
+ if (current.kind !== 'connected' || current.appId !== event.contextId || im.getOwnerOpenId() !== event.senderId) {
+ throw new ImAccountScopeClosedError();
+ }
+ if (!row?.workingDir || row.status === 'deleted' || row.status === 'archived' || row.orcaRole === 'worker') {
+ throw new Error('Notification target session is unavailable');
+ }
+ log.info('notification reply resolved', { root: event.replyThread.rootMessageId.slice(-8), session: origin.sessionId.slice(-8) });
+ return origin.sessionId;
+}
diff --git a/apps/desktop/src/main/im/shared/__tests__/earlyUserMessagePersist.test.ts b/apps/desktop/src/main/im/shared/__tests__/earlyUserMessagePersist.test.ts
index 839df01e76..d9367d0bce 100644
--- a/apps/desktop/src/main/im/shared/__tests__/earlyUserMessagePersist.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/earlyUserMessagePersist.test.ts
@@ -65,7 +65,7 @@ interface Harness {
reactToMessage: ReturnType<typeof vi.fn>;
}
-function wire(opts: { withPrepare: boolean } = { withPrepare: true }): Harness {
+function wire(opts: { withPrepare: boolean; notificationSessionId?: string } = { withPrepare: true }): Harness {
const calls: string[] = [];
const runAgentTurn = vi.fn(async () => undefined);
const reactToMessage = vi.fn(async () => 'reaction-1');
@@ -96,6 +96,7 @@ function wire(opts: { withPrepare: boolean } = { withPrepare: true }): Harness {
const adapter = {
channel: 'feishu',
+ ...(opts.notificationSessionId ? { resolveNotificationReply: async () => opts.notificationSessionId } : {}),
im,
ui: slackUi,
threadScoped: false,
@@ -195,3 +196,14 @@ describe('messageHandler early user-message persist', () => {
expect(turnArgs(h.runAgentTurn).prePersistedUserMessage).toBeUndefined();
});
});
+
+
+it('does not persist a notification reply into the default IM session before dispatch', async () => {
+ activateImAccountBoundary();
+ const h = wire({ withPrepare: true, notificationSessionId: 'original-session' });
+ h.deliver(makeEvent({ senderId: 'ou_owner', replyThread: { rootMessageId: 'om_root', threadId: 'omt_topic' } }));
+ await vi.waitFor(() => expect(h.runAgentTurn).toHaveBeenCalledWith(expect.objectContaining({
+ notificationSessionId: 'original-session', scopeKey: 'om_root',
+ })));
+ expect(h.persistEarly).not.toHaveBeenCalled();
+});
diff --git a/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts b/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts
index 3c6f49eb13..de79669d88 100644
--- a/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/stopCommandRouting.test.ts
@@ -97,7 +97,7 @@ describe('messageHandler !stop routing', () => {
let consumePendingOpenerAsCard: ReturnType<typeof vi.fn>;
let deliver: (event: IMMessageEvent) => void;
- function wire(threadScoped: boolean): void {
+ function wire(threadScoped: boolean, notificationSessionId?: string): void {
stopActiveTurn = vi.fn(async () => ({ stopped: true, droppedQueued: 0 }));
runAgentTurn = vi.fn(async () => undefined);
handleSlashCommand = vi.fn(async () => true);
@@ -120,6 +120,10 @@ describe('messageHandler !stop routing', () => {
const adapter = {
channel: 'slack',
+ ...(notificationSessionId ? {
+ resolveNotificationReply: async () => notificationSessionId,
+ notificationReplyText: { unavailable: 'unavailable', commands: 'topic commands' },
+ } : {}),
im,
output: { kind: 'rich-card', im },
ui: slackUi,
@@ -141,6 +145,24 @@ describe('messageHandler !stop routing', () => {
wire(true);
});
+ it('routes topic !stop to the original session even while /ctr is open elsewhere', async () => {
+ wire(false, 'original-session');
+ enterControl('bot-ctx', 'U123456789');
+ deliver(makeEvent({ replyThread: { rootMessageId: 'om_root', threadId: 'omt_topic' } }));
+ await vi.waitFor(() => expect(stopActiveTurn).toHaveBeenCalledWith({
+ botContextId: 'bot-ctx', userId: 'U123456789', scopeKey: 'om_root', notificationSessionId: 'original-session',
+ }));
+ expect(runAgentTurn).not.toHaveBeenCalled();
+ });
+
+ it('keeps slash commands in linked topics from changing the main conversation', async () => {
+ wire(false, 'original-session');
+ deliver(makeEvent({ text: '/new', replyThread: { rootMessageId: 'om_root', threadId: 'omt_topic' } }));
+ await vi.waitFor(() => expect(sendMarkdownText).toHaveBeenCalledWith('U123456789', 'topic commands', { threadTs: 'om_root' }));
+ expect(handleSlashCommand).not.toHaveBeenCalled();
+ expect(runAgentTurn).not.toHaveBeenCalled();
+ });
+
it('silently drops messages delivered after logout closes the account boundary', async () => {
deactivateImAccountBoundary();
deliver(makeEvent({ text: 'after logout' }));
diff --git a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
index 43cf6d6ccf..83b4a87826 100644
--- a/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/turnRunnerThreadRouting.test.ts
@@ -127,6 +127,7 @@ function makeSessionHarness(sessionId: string): SessionHarness {
const session = {
id: sessionId,
agentKind: 'claude-code',
+ abort: vi.fn(async () => undefined),
send,
isTurnRunning: vi.fn(() => false),
onEvent(listener: (event: AgentEvent) => void) {
@@ -656,3 +657,81 @@ describe('turnRunner 自动任务转播(scheduler turn → 远程控制 thread)'
expect(finalBody).toContain('重试后成功');
});
});
+
+describe('notification replies reuse the originating session without takeover', () => {
+ function origin(status = 'active') {
+ mocks.dbSelect.mockReturnValue({ from: () => ({ where: () => ({ limit: async () => [{
+ ...rowFor('original-session'), sdkSessionId: 'original-sdk-session', status,
+ }] }) }) });
+ }
+ const reply = (scopeKey: string) => runner.runAgentTurn({
+ notificationSessionId: 'original-session', botContextId: 'T1', userId: 'U1',
+ userMessageId: `reply-${scopeKey}`, text: 'continue', attachments: [], scopeKey,
+ });
+
+ it('resumes the original SDK session without changing bindings or moving desktop interactions', async () => {
+ origin();
+ await reply('om_notification_a');
+ expect(fakeRepo.createSession).not.toHaveBeenCalled();
+ expect(mocks.bindingGet).not.toHaveBeenCalled();
+ expect(mocks.takePendingInteractionsForSession).not.toHaveBeenCalled();
+ expect(mocks.getMaker().createSession).toHaveBeenCalledWith(expect.objectContaining({
+ id: 'original-session', resumeSessionId: 'original-sdk-session', vendorOptions: undefined,
+ }));
+ expect(harnesses.get('original-session')!.send).toHaveBeenCalledTimes(1);
+ });
+
+ it('queues different topics on the same session and sends each final result to its own root', async () => {
+ origin();
+ await reply('om_notification_a');
+ await reply('om_notification_b');
+ const h = harnesses.get('original-session')!;
+ expect(h.send).toHaveBeenCalledTimes(1);
+ h.emit({ type: 'text', data: { text: 'first' } } as AgentEvent);
+ await vi.waitFor(() => expect(mocks.slackIm.startStreamingText).toHaveBeenCalledWith('U1', undefined, { threadTs: 'om_notification_a' }));
+ h.emit({ type: 'done' } as AgentEvent);
+ await vi.waitFor(() => expect(h.send).toHaveBeenCalledTimes(2));
+ h.emit({ type: 'text', data: { text: 'second' } } as AgentEvent);
+ await vi.waitFor(() => expect(mocks.slackIm.startStreamingText).toHaveBeenCalledWith('U1', undefined, { threadTs: 'om_notification_b' }));
+ h.emit({ type: 'done' } as AgentEvent);
+ expect(fakeRepo.createSession).not.toHaveBeenCalled();
+ });
+
+ it('revalidates a queued reply before invoking the original session', async () => {
+ origin();
+ await reply('om_notification_a');
+ const revalidateNotificationReply = vi.fn(async () => { throw new Error('bot changed'); });
+ await runner.runAgentTurn({
+ notificationSessionId: 'original-session', revalidateNotificationReply,
+ botContextId: 'T1', userId: 'U1', userMessageId: 'reply-b',
+ text: 'continue', attachments: [], scopeKey: 'om_notification_b',
+ });
+ expect(revalidateNotificationReply).not.toHaveBeenCalled();
+ const h = harnesses.get('original-session')!;
+ h.emit({ type: 'done' } as AgentEvent);
+ await vi.waitFor(() => expect(revalidateNotificationReply).toHaveBeenCalledTimes(1));
+ expect(h.send).toHaveBeenCalledTimes(1);
+ expect(fakeRepo.createSession).not.toHaveBeenCalled();
+ });
+
+ it('stopping a queued topic never aborts the active turn from another topic', async () => {
+ origin();
+ await reply('om_notification_a');
+ await reply('om_notification_b');
+ const h = harnesses.get('original-session')!;
+ await expect(runner.stopActiveTurn({
+ notificationSessionId: 'original-session', botContextId: 'T1', userId: 'U1', scopeKey: 'om_notification_b',
+ })).resolves.toEqual({ stopped: true, droppedQueued: 1 });
+ expect(h.session.abort).not.toHaveBeenCalled();
+ h.emit({ type: 'done' } as AgentEvent);
+ await new Promise((resolve) => setTimeout(resolve, 10));
+ expect(h.send).toHaveBeenCalledTimes(1);
+ });
+
+ it('rejects an archived origin rather than creating another session', async () => {
+ origin('archived');
+ await expect(reply('om_notification_a')).rejects.toThrow('Notification target session is unavailable');
+ expect(fakeRepo.createSession).not.toHaveBeenCalled();
+ expect(harnesses.size).toBe(0);
+ });
+});
diff --git a/apps/desktop/src/main/im/shared/messageHandler.ts b/apps/desktop/src/main/im/shared/messageHandler.ts
index 34ce820345..5caac1a5a0 100644
--- a/apps/desktop/src/main/im/shared/messageHandler.ts
+++ b/apps/desktop/src/main/im/shared/messageHandler.ts
@@ -126,6 +126,27 @@ export function createMessageHandler(
return;
}
+ let notificationSessionId: string | undefined;
+ if (event.replyThread && adapter.resolveNotificationReply) {
+ try {
+ notificationSessionId = (await adapter.resolveNotificationReply(event)) ?? undefined;
+ } catch (error) {
+ if (isImAccountScopeClosedError(error)) throw error;
+ log.warn('notification reply route unavailable');
+ await im.sendMarkdownText(event.senderId, adapter.notificationReplyText!.unavailable, {
+ threadTs: event.replyThread.rootMessageId,
+ });
+ return;
+ }
+ if (notificationSessionId) {
+ event = { ...event, scopeKey: event.replyThread.rootMessageId };
+ if (pureTextCommandInput && looksLikeSlashCommand(event.text)) {
+ await im.sendMarkdownText(event.senderId, adapter.notificationReplyText!.commands, { threadTs: event.scopeKey });
+ return;
+ }
+ }
+ }
+
// ── /ctr 原子化拦截 ────────────────────────────────────────────────
// 该 (bot, owner) 处于 /ctr 流程中 → 任何消息都不路由到 slash/agent,
// 直接回提示让用户走卡片按钮 (back/exit/session-pick) 退出。包括重复
@@ -138,7 +159,7 @@ export function createMessageHandler(
? isInControl(event.contextId, event.senderId) &&
(!event.threadTs || event.threadTs === getControlScope(event.contextId, event.senderId))
: isInControl(event.contextId, event.senderId);
- if (blockedByControl) {
+ if (blockedByControl && !notificationSessionId) {
log.info(
`dropped (in /ctr) sender=...${event.senderId.slice(-8)} bot=...${event.contextId.slice(-8)}`,
);
@@ -163,7 +184,8 @@ export function createMessageHandler(
const result = await turnRunner.stopActiveTurn({
botContextId: event.contextId,
userId: event.senderId,
- scopeKey: threadScoped ? event.scopeKey : undefined,
+ scopeKey: notificationSessionId || threadScoped ? event.scopeKey : undefined,
+ ...(notificationSessionId ? { notificationSessionId } : {}),
});
reply = result.stopped ? ui.agent.stopDone(result.droppedQueued) : ui.agent.stopIdle;
log.info(
@@ -323,15 +345,17 @@ export function createMessageHandler(
if (adapter.prepareAgentTurnText) {
handedOverAck = event.messageId ? ackProcessingEarly(im, event.messageId) : null;
try {
- prePersisted =
- (await turnRunner.persistInboundUserMessageEarly?.({
- botContextId: event.contextId,
- userId: event.senderId,
- scopeKey: threadScoped ? event.scopeKey : undefined,
- text: event.text,
- attachments: event.attachments,
- ...(event.protectedContent === true ? { protectedContent: true } : {}),
- })) ?? null;
+ if (!notificationSessionId) {
+ prePersisted =
+ (await turnRunner.persistInboundUserMessageEarly?.({
+ botContextId: event.contextId,
+ userId: event.senderId,
+ scopeKey: threadScoped ? event.scopeKey : undefined,
+ text: event.text,
+ attachments: event.attachments,
+ ...(event.protectedContent === true ? { protectedContent: true } : {}),
+ })) ?? null;
+ }
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
log.warn(`early user-message persist failed (non-fatal): ${msg}`);
@@ -348,6 +372,14 @@ export function createMessageHandler(
const groupHistoryAccess = adapter.groupHistoryAccessFor?.(event);
try {
await turnRunner.runAgentTurn({
+ ...(notificationSessionId ? {
+ notificationSessionId,
+ revalidateNotificationReply: async () => {
+ if (await adapter.resolveNotificationReply!(event) !== notificationSessionId) {
+ throw new Error('Notification reply identity changed before dispatch');
+ }
+ },
+ } : {}),
botContextId: event.contextId,
userId: event.senderId,
userMessageId: event.messageId,
@@ -386,7 +418,7 @@ export function createMessageHandler(
: {}),
attachments: event.attachments,
// threadScoped 渠道: scopeKey = thread root ts(thread = session 路由键)
- scopeKey: threadScoped ? event.scopeKey : undefined,
+ scopeKey: notificationSessionId || threadScoped ? event.scopeKey : undefined,
// Title generation and similar detached work must stay visible to the
// same account drain without delaying the foreground message dispatch.
trackBackgroundTask: (operation) => {
@@ -405,7 +437,10 @@ export function createMessageHandler(
log.error(`runAgentTurn threw: ${msg}`);
// 本条消息自己开了话题(groupContextLane)时, 开场白卡还没被流式认领 —
// 用内部错误内容收口它, 否则卡永久残留且同话题下一条会 patch 错卡。
- const errorText = ui.agent.sendInternalError(msg);
+ if (isImAccountScopeClosedError(err)) throw err;
+ const errorText = notificationSessionId
+ ? adapter.notificationReplyText!.unavailable
+ : ui.agent.sendInternalError(msg);
const openerConsumed = event.groupContextLane
? await consumeOpenerWithText(event.senderId, errorText)
: false;
diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.ts
index eece7d23c0..c3b5dc166e 100644
--- a/apps/desktop/src/main/im/shared/turnRunner.ts
+++ b/apps/desktop/src/main/im/shared/turnRunner.ts
@@ -194,6 +194,9 @@ interface TurnState {
/** thread = session 模型的会话维度键(slack thread root ts);feishu undefined。 */
scopeKey?: string;
initialMessageText: string;
+ reusesExistingSession?: boolean;
+ notificationReply?: boolean;
+ revalidateNotificationReply?: () => Promise<void>;
/** First text-delta resolves this lazily (avoids creating a card for empty turns). */
streamingHandle: StreamingTextHandle | null;
/**
@@ -302,6 +305,8 @@ interface QueuedSend {
type DetachDrainOutcome = 'rewire' | 'cancelled';
interface SessionState {
+ /** Keep the original session configuration even when no persistent takeover exists. */
+ preserveSessionConfig: boolean;
/** Maker session (in-process). */
makerSession: MakerSession;
/** 渠道 user id of the bot's owner — kept here so listeners can address replies. */
@@ -364,6 +369,8 @@ interface ScheduledTranspond {
* 未命中 → 渠道默认 session (attached=false, B' 行为)。
*/
export interface RouteTarget {
+ /** Reply to a notification: reuse session configuration without persistent takeover. */
+ notificationReply?: boolean;
row: ImSessionRow;
attached: boolean;
/** 路由时使用的会话维度键(thread root ts)— 透传给出站回复定位 thread。 */
@@ -380,6 +387,9 @@ type DefaultRouteTargetResolution =
export interface ImRunAgentTurnArgs {
contextSnapshot?: ImContextSnapshot;
+ /** Main-owned, resolved from an authenticated provider notification receipt. */
+ notificationSessionId?: string;
+ revalidateNotificationReply?: () => Promise<void>;
botContextId: string;
userId: string;
/** 渠道 message id of the user's incoming message — used for emoji ack. */
@@ -532,6 +542,7 @@ export interface ImTurnRunner {
* 该路径绝不新建 session 行。
*/
stopActiveTurn(args: {
+ notificationSessionId?: string;
botContextId: string;
userId: string;
scopeKey?: string;
@@ -606,6 +617,20 @@ export function createTurnRunner(
});
}
+ async function resolveNotificationTarget(sessionId: string, scopeKey?: string): Promise<RouteTarget> {
+ const [row] = await getDbClient().drizzle.select().from(sessionsTable)
+ .where(eq(sessionsTable.id, sessionId)).limit(1);
+ if (!row?.workingDir || row.status === 'deleted' || row.status === 'archived' || row.orcaRole === 'worker') {
+ throw new Error('Notification target session is unavailable');
+ }
+ return {
+ row: { id: row.id, agentKind: toCoreAgentKind(row.agentKind), workingDir: row.workingDir,
+ model: row.model, effort: row.effort, permissionMode: row.permissionMode, fastMode: row.fastMode,
+ sdkSessionId: row.sdkSessionId, remoteHostId: row.remoteHostId ?? null, providerId: row.providerId ?? null },
+ attached: false, notificationReply: true, scopeKey,
+ };
+ }
+
async function resolveRouteTarget(
botContextId: string,
userId: string,
@@ -718,7 +743,9 @@ export function createTurnRunner(
// 路由分流 — 先查 binding: 命中走 desktop session (接管模式 C),
// 未命中走渠道默认 session (B' 行为)。这是 /ctr 接管能生效的关键入口。
- let target = await resolveExistingRouteTarget(botContextId, userId, scopeKey);
+ let target = args.notificationSessionId
+ ? await resolveNotificationTarget(args.notificationSessionId, scopeKey)
+ : await resolveExistingRouteTarget(botContextId, userId, scopeKey);
if (!target) {
const created = await createAuthenticatedDefaultRouteTarget(botContextId, userId, scopeKey);
if (!created.target) {
@@ -803,6 +830,9 @@ export function createTurnRunner(
userId,
scopeKey: target.scopeKey,
initialMessageText: text,
+ reusesExistingSession: target.attached || target.notificationReply,
+ notificationReply: target.notificationReply,
+ revalidateNotificationReply: args.revalidateNotificationReply,
streamingHandle: null,
streamingHandlePromise: null,
streamingStartFailed: false,
@@ -883,6 +913,7 @@ export function createTurnRunner(
}),
);
} else if (
+ !target.notificationReply &&
titleFromText &&
text.trim().length > 0 &&
(adapter.threadScoped
@@ -909,7 +940,7 @@ export function createTurnRunner(
userMessage: buildImUserMessage(
args.agentText ?? text,
[...attachments, ...(args.contextAttachments ?? [])],
- target.attached,
+ target.attached || target.notificationReply === true,
),
rowId: row.id,
text,
@@ -1016,6 +1047,7 @@ export function createTurnRunner(
): Promise<
{ kind: 'accepted'; acceptedAt: number } | { kind: 'busy' | 'rejected'; reason: string }
> {
+ userId = item.turn.userId;
const rowId = item.rowId;
await beginChunkedReply(item.turn);
// 过程区耗时基准取真实派发时刻 — TurnState 创建时可能还要在 sendQueue 里
@@ -1030,6 +1062,10 @@ export function createTurnRunner(
let releaseAgentSwitchLock = (): void => {};
try {
+ if (item.turn.notificationReply) {
+ await item.turn.revalidateNotificationReply?.();
+ await resolveNotificationTarget(rowId, item.turn.scopeKey);
+ }
// deferred 切换会关闭旧 session。apply 成功后重新读取 maker 里的 live
// session 并原地换绑 IM listener,确保当前这条消息发给目标引擎且队列不丢。
if (deps.acquirePendingAgentSwitch) {
@@ -1100,7 +1136,7 @@ export function createTurnRunner(
...(effectiveTurnPolicy ? { turnPermissionPolicy: effectiveTurnPolicy } : {}),
beforeProviderStart: async () => {
const noticeSession = state.makerSession;
- const noticeScope = state.scopeKey;
+ const noticeScope = item.turn.scopeKey;
bindRuntimeRecoveryNotice(noticeSession, async (text) => {
if (sessionStates.get(rowId)?.makerSession !== noticeSession) return false;
return im.sendText(userId, text, { threadTs: noticeScope });
@@ -1155,7 +1191,7 @@ export function createTurnRunner(
handle: handleInteractionFor(
rowId,
userId,
- state.scopeKey,
+ item.turn.scopeKey,
effectiveTurnPolicy?.confirmationTimeoutMs,
),
// 文本渠道自己认领掉的不动卡片(它本来就没有卡);其余走
@@ -1179,7 +1215,7 @@ export function createTurnRunner(
// dispatch 起将 Setup 交互视为 headless。未接管的渠道 session 已由
// vendorOptions.source 标识,不需要 marker。若本 turn 已终止,跳过迟到
// callback 的落库等陈旧副作用。
- if (!markAttachedImTurnHeadlessDispatched(item.turn, rowId, state.attached)) return;
+ if (!markAttachedImTurnHeadlessDispatched(item.turn, rowId, item.turn.reusesExistingSession === true)) return;
// 真实用户消息 → 给 silent-stop 守卫充值自动续跑额度(renderer 发送
// 走 createMakerSendTransaction 内部已充值;scheduler / hook 与本
// 路径直接 session.send,必须额外调这里,否则守卫额度恒 0,首次
@@ -1278,7 +1314,7 @@ export function createTurnRunner(
userId,
text: ui.agent.sendInternalError('session_detaching'),
terminal: 'error',
- threadTs: state.scopeKey,
+ threadTs: item.turn.scopeKey,
errorCode: 'session_detaching',
});
} catch {
@@ -1390,7 +1426,7 @@ export function createTurnRunner(
providerId: row.providerId,
remoteHostId: row.remoteHostId ?? undefined,
resumeSessionId: row.sdkSessionId ?? undefined,
- vendorOptions: state.attached
+ vendorOptions: state.preserveSessionConfig
? undefined
: adapter.buildVendorOptions(userId, state.scopeKey),
});
@@ -1471,6 +1507,15 @@ export function createTurnRunner(
}
return ensureSessionWired(target, userId);
}
+ if (target.attached && !existing.attached) {
+ existing.attached = true;
+ existing.preserveSessionConfig = true;
+ existing.userId = userId;
+ existing.scopeKey = target.scopeKey;
+ for (const entry of takePendingInteractionsForSession(target.row.id)) {
+ void publishMigratedInteraction(entry, userId, target.row.id, target.scopeKey);
+ }
+ }
return existing;
}
const inFlight = wiringInFlight.get(target.row.id);
@@ -1568,6 +1613,7 @@ export function createTurnRunner(
async function wireSessionInternal(target: RouteTarget, userId: string): Promise<SessionState> {
const { row, attached } = target;
+ const preserveSessionConfig = attached || target.notificationReply === true;
const maker = getMaker();
ensureMakerCloseSubscription(maker);
@@ -1578,7 +1624,7 @@ export function createTurnRunner(
// vendorOptions, 保持 B' 行为不变。
// 注: maker.createSession({id}) 是按 id 单例, 命中 activeSessions 直接复用,
// 这里传的 vendorOptions 只在首次 spawn 时生效。
- const vendorOptions = attached
+ const vendorOptions = preserveSessionConfig
? undefined
: adapter.buildVendorOptions(userId, target.scopeKey);
// 把会话持久化的 providerId 灌进 session-provider-store —— 路由层(loopback proxy
@@ -1608,7 +1654,7 @@ export function createTurnRunner(
remoteHostId: row.remoteHostId ?? undefined,
// 行总是先由 repo 建好, maker 复用已有 row 时该 title 不会生效 —
// 仅作防御兜底(原 feishu 实现传 '飞书会话' 字面量, 语义等价)。
- title: attached ? undefined : adapter.sessions.defaultTitle(userId),
+ title: preserveSessionConfig ? undefined : adapter.sessions.defaultTitle(userId),
vendorOptions,
resumeSessionId: row.sdkSessionId ?? undefined,
});
@@ -1627,6 +1673,7 @@ export function createTurnRunner(
const state: SessionState = {
makerSession,
+ preserveSessionConfig,
userId,
workingDir: row.workingDir,
scopeKey: target.scopeKey,
@@ -2595,6 +2642,7 @@ export function createTurnRunner(
onEarlyReject?: (reason: string, text: string) => Promise<boolean> | boolean;
},
): Promise<void> {
+ userId = failure.turn.userId;
log.error(`${channel} session send failed before dispatch`, {
kind: 'session-dispatch',
source: failure.source,
@@ -2646,11 +2694,11 @@ export function createTurnRunner(
userId,
text: message,
terminal: 'error',
- threadTs: state.scopeKey,
+ threadTs: failure.turn.scopeKey,
errorCode: failure.reason,
});
} else {
- await sendTextClaimingOpener(userId, message, state.scopeKey);
+ await sendTextClaimingOpener(userId, message, failure.turn.scopeKey);
}
}
// 群会话「完全访问」档被强确认策略拒绝: 报错文案之外, 再给 owner
@@ -2902,6 +2950,7 @@ export function createTurnRunner(
async function handleTurnDoneAsync(state: SessionState, userId: string): Promise<void> {
const turn = state.queue.shift();
if (!turn) return;
+ userId = turn.userId;
clearSilentStopSettleWait(turn);
turn.done = true;
clearActivityTicker(turn);
@@ -2935,7 +2984,7 @@ export function createTurnRunner(
userId,
text: '✅ (本轮无文本输出)',
terminal: turn.terminalKind,
- threadTs: state.scopeKey,
+ threadTs: turn.scopeKey,
...(turn.mediaAbsPaths.length > 0 ? { mediaAbsPaths: turn.mediaAbsPaths } : {}),
});
} else {
@@ -2950,7 +2999,7 @@ export function createTurnRunner(
false)
: false;
if (!consumed) {
- await sendTextClaimingOpener(userId, '✅ (本轮无文本输出)', state.scopeKey);
+ await sendTextClaimingOpener(userId, '✅ (本轮无文本输出)', turn.scopeKey);
}
}
} catch {
@@ -2968,11 +3017,11 @@ export function createTurnRunner(
userId,
text: fallbackText,
terminal: turn.terminalKind,
- threadTs: state.scopeKey,
+ threadTs: turn.scopeKey,
...(turn.mediaAbsPaths.length > 0 ? { mediaAbsPaths: turn.mediaAbsPaths } : {}),
});
} else {
- await output.im.sendText(userId, fallbackText, { threadTs: state.scopeKey });
+ await output.im.sendText(userId, fallbackText, { threadTs: turn.scopeKey });
}
log.info(`[${channel}/turn] streaming surface unavailable — final text delivered via plain send`);
} catch (err) {
@@ -2999,6 +3048,8 @@ export function createTurnRunner(
errData: unknown,
): Promise<void> {
const turn = state.queue.shift();
+ if (!turn) return;
+ userId = turn.userId;
const rawMsg =
errData && typeof errData === 'object' && 'message' in errData
? String((errData as { message: unknown }).message)
@@ -3046,7 +3097,7 @@ export function createTurnRunner(
userId,
text: `❌ 错误:${msg}`,
terminal: 'error',
- threadTs: state.scopeKey,
+ threadTs: turn.scopeKey,
errorCode: turn?.terminalErrorCode ?? 'agent_turn_error',
...(turn && turn.mediaAbsPaths.length > 0 ? { mediaAbsPaths: turn.mediaAbsPaths } : {}),
});
@@ -3059,7 +3110,7 @@ export function createTurnRunner(
? ((await output.im.consumePendingOpenerCard?.(userId, errorText)) ?? false)
: false;
if (!consumed) {
- await sendTextClaimingOpener(userId, errorText, state.scopeKey);
+ await sendTextClaimingOpener(userId, errorText, turn.scopeKey);
}
}
} catch {
@@ -3505,15 +3556,33 @@ export function createTurnRunner(
}
async function stopActiveTurn(args: {
+ notificationSessionId?: string;
botContextId: string;
userId: string;
scopeKey?: string;
}): Promise<{ stopped: boolean; droppedQueued: number }> {
const { botContextId, userId, scopeKey } = args;
// 只解析既有路由 — !stop 不该为不存在的会话新建 session 行。
- const target = await resolveExistingRouteTarget(botContextId, userId, scopeKey);
+ const target = args.notificationSessionId
+ ? await resolveNotificationTarget(args.notificationSessionId, scopeKey)
+ : await resolveExistingRouteTarget(botContextId, userId, scopeKey);
const state = target ? sessionStates.get(target.row.id) : undefined;
if (!state) return { stopped: false, droppedQueued: 0 };
+ if (args.notificationSessionId) {
+ const matches = (turn: TurnState) => turn.userId === userId && turn.scopeKey === scopeKey;
+ const removed = state.sendQueue.filter((item) => matches(item.turn));
+ state.sendQueue = state.sendQueue.filter((item) => !matches(item.turn));
+ for (const item of removed) {
+ item.turn.terminalKind = 'aborted';
+ void completeTurnCallbackAfterAck(item.turn);
+ }
+ const active = state.queue[0];
+ if (!active || !matches(active)) return { stopped: removed.length > 0, droppedQueued: removed.length };
+ noteSilentStopSessionReset(state.makerSession.id);
+ active.terminalKind = 'aborted';
+ await state.makerSession.abort();
+ return { stopped: true, droppedQueued: removed.length };
+ }
const running =
state.queue.length > 0 || state.sendQueue.length > 0 || state.makerSession.isTurnRunning();
if (!running) return { stopped: false, droppedQueued: 0 };
diff --git a/apps/desktop/src/main/im/shared/types.ts b/apps/desktop/src/main/im/shared/types.ts
index 7f91c787e7..1cdb1b145a 100644
--- a/apps/desktop/src/main/im/shared/types.ts
+++ b/apps/desktop/src/main/im/shared/types.ts
@@ -137,6 +137,10 @@ export interface ImSessionNamespace {
* 渠道适配器 — 编排层所有渠道差异的唯一注入点。
*/
export interface ImChannelAdapter {
+ /** Resolve an authenticated private notification topic before any default-session or command routing. */
+ resolveNotificationReply?: (event: IMMessageEvent) => Promise<string | null>;
+ notificationReplyText?: { unavailable: string; commands: string };
+
channel: ImChannelName;
/** Selected display service; defaults to channel without changing routing identity. */
messageSourceIm?(): string;
diff --git a/apps/desktop/src/main/localDb/schema.ts b/apps/desktop/src/main/localDb/schema.ts
index ca11e500b6..50b67646c1 100644
--- a/apps/desktop/src/main/localDb/schema.ts
+++ b/apps/desktop/src/main/localDb/schema.ts
@@ -893,6 +893,21 @@ export const accountUsageSnapshots = sqliteTable('account_usage_snapshots', {
updatedAt: integer('updated_at').notNull(),
});
+/** Provider notification receipts. Retain the source id after session deletion to reject stale replies. */
+export const imNotificationOrigins = sqliteTable(
+ 'im_notification_origins',
+ {
+ channel: text('channel').notNull(),
+ botContextId: text('bot_context_id').notNull(),
+ userId: text('user_id').notNull(),
+ messageId: text('message_id').notNull(),
+ chatId: text('chat_id').notNull(),
+ sessionId: text('session_id').notNull(),
+ createdAt: integer('created_at').notNull(),
+ },
+ (t) => ({ pk: primaryKey({ columns: [t.channel, t.botContextId, t.userId, t.messageId] }) }),
+);
+
/**
* IM 身份 → desktop session 的接管绑定表 (feishu /ctr 流程产物)。
*
diff --git a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
index 4300a51173..c4922a08e4 100644
--- a/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
+++ b/apps/desktop/src/main/mcp-integrations/mcp-providers.ts
@@ -32,6 +32,7 @@ import { getIOSSimulatorMcpDeps } from './ios-simulator.js';
import { getBrowserMcpDeps } from './browser.js';
import { getComputerMcpDeps } from './computer.js';
import { feishuIm, wechatIm } from '../im';
+import { sendFeishuSessionNotification } from '../im/feishu/notificationOrigin';
import { getSlackToolBridge } from '../hook-control/slackToolBridge.js';
import { createLogger } from '../logger.js';
import { getScheduler } from '../scheduler-host/index.js';
@@ -192,8 +193,14 @@ export function createDesktopMcpProviders(deps: DesktopMcpProvidersDeps): LiziMc
// branch-free. Feishu returns 400 with structured `response.data.code/msg`
// for business errors (rate-limit, invalid text, …); those get folded
// into `reason` for logging without leaking axios internals to the tool.
- sendMessage: async (chatId, markdown) => {
+ sendMessage: async (chatId, markdown, notificationSessionId) => {
try {
+ if (notificationSessionId && chatId === feishuIm.getOwnerOpenId()) {
+ const { messageId, sessionLinked } = await sendFeishuSessionNotification(
+ feishuIm, notificationSessionId, markdown,
+ );
+ return { ok: true, messageId, sessionLinked };
+ }
const { messageId } = await feishuIm.sendMarkdownText(chatId, markdown);
return { ok: true, messageId };
} catch (err) {
diff --git a/apps/desktop/src/main/scheduler-host/__tests__/notifier.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/notifier.test.ts
index 40f52687f0..d6d5edcb86 100644
--- a/apps/desktop/src/main/scheduler-host/__tests__/notifier.test.ts
+++ b/apps/desktop/src/main/scheduler-host/__tests__/notifier.test.ts
@@ -35,6 +35,7 @@ function run(status: ScheduleRun['status']): ScheduleRun {
}
function createNotifier(opts?: {
+ sendFeishuSessionNotification?: (sessionId: string, text: string) => Promise<void>;
sendMarkdownText?: ReturnType<typeof vi.fn>;
shouldNotifyDesktop?: () => boolean;
isAgentIslandEnabled?: () => boolean;
@@ -49,6 +50,7 @@ function createNotifier(opts?: {
const warn = vi.fn();
const publishMarkdown = opts?.publishMarkdown ?? vi.fn(async () => undefined);
const notifier = new DesktopNotifier({
+ sendFeishuSessionNotification: opts?.sendFeishuSessionNotification,
getMainWindow: () => null as BrowserWindow | null,
feishuIm: {
getOwnerOpenId: vi.fn(() => 'ou_owner'),
@@ -254,3 +256,23 @@ describe('DesktopNotifier desktop status mapping', () => {
expect(published).not.toContain('C:/private/report.txt');
});
});
+
+
+describe('Feishu notification origin receipt', () => {
+ it('passes the original run session to the receipt writer', async () => {
+ const sendFeishuSessionNotification = vi.fn(async () => undefined);
+ const { notifier, sendMarkdownText } = createNotifier({ sendFeishuSessionNotification });
+ await notifier.notify({ ...schedule, notify: { desktop: false, feishu: true } }, run('success'));
+ expect(sendFeishuSessionNotification).toHaveBeenCalledWith('session-1', expect.any(String));
+ expect(sendMarkdownText).not.toHaveBeenCalled();
+ });
+
+ it('does not resend a notification if receipt persistence fails', async () => {
+ const sendFeishuSessionNotification = vi.fn(async () => { throw new Error('receipt write failed'); });
+ const { notifier, sendMarkdownText, warn } = createNotifier({ sendFeishuSessionNotification });
+ await notifier.notify({ ...schedule, notify: { desktop: false, feishu: true } }, run('success'));
+ expect(sendFeishuSessionNotification).toHaveBeenCalledTimes(1);
+ expect(sendMarkdownText).not.toHaveBeenCalled();
+ expect(warn).toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/main/scheduler-host/index.ts b/apps/desktop/src/main/scheduler-host/index.ts
index dcbf5ba8fa..de73189df3 100644
--- a/apps/desktop/src/main/scheduler-host/index.ts
+++ b/apps/desktop/src/main/scheduler-host/index.ts
@@ -54,6 +54,7 @@ import { buildForcedFailureRun } from './forcedFailureRun';
import { ScriptScheduleRunner } from './script-runner';
import { SchedulerScriptCapabilityBroker } from './script-capability-broker';
import { DesktopNotifier } from './notifier';
+import { sendFeishuSessionNotification } from '../im/feishu/notificationOrigin';
import { withScheduleLock } from './scheduleLock';
import { wecomGroupNotificationService } from '../wecomGroupNotification';
import { runSchedulerStartup } from './scheduler-startup-lifecycle';
@@ -97,6 +98,9 @@ async function startSchedulerInternal(deps: StartSchedulerDeps): Promise<Schedul
const storage = new DrizzleScheduleStorage(deps.getDb);
_storage = storage;
const notifier = new DesktopNotifier({
+ sendFeishuSessionNotification: async (sessionId, text) => {
+ await sendFeishuSessionNotification(deps.feishuIm, sessionId, text);
+ },
getMainWindow: deps.getMainWindow,
feishuIm: deps.feishuIm,
logger: deps.logger,
diff --git a/apps/desktop/src/main/scheduler-host/notifier.ts b/apps/desktop/src/main/scheduler-host/notifier.ts
index 080178bbcc..b5ed5964e5 100644
--- a/apps/desktop/src/main/scheduler-host/notifier.ts
+++ b/apps/desktop/src/main/scheduler-host/notifier.ts
@@ -25,6 +25,8 @@ export interface DesktopNotifierDeps {
getMainWindow: () => BrowserWindow | null;
feishuIm: FeishuIM;
logger: Logger;
+ /** Persist the notification receipt against this exact run, when a session exists. */
+ sendFeishuSessionNotification?: (sessionId: string, text: string) => Promise<void>;
/** Global desktop preference, evaluated at send time. */
shouldNotifyDesktop: () => boolean;
/** Whether Agent Island should arbitrate routine scheduler desktop notifications. */
@@ -107,7 +109,11 @@ export class DesktopNotifier implements Notifier {
}
const text = renderExternalMessage(schedule, run);
try {
- await this.deps.feishuIm.sendMarkdownText(ownerOpenId, text);
+ if (run.sessionId && this.deps.sendFeishuSessionNotification) {
+ await this.deps.sendFeishuSessionNotification(run.sessionId, text);
+ } else {
+ await this.deps.feishuIm.sendMarkdownText(ownerOpenId, text);
+ }
} catch (err) {
// 飞书 SDK 包了一层 axios; 400 等业务错误的真正 message 在 response.data.code/msg
// 里, axios.toString() 看不到。显式拆出来 log, 否则只看到 'Request failed
diff --git a/packages/lizi-im/src/channelIM.ts b/packages/lizi-im/src/channelIM.ts
index b8ef7783b4..7437dfefeb 100644
--- a/packages/lizi-im/src/channelIM.ts
+++ b/packages/lizi-im/src/channelIM.ts
@@ -35,9 +35,8 @@ export interface TextChannelIM {
onStatusChange(handler: (s: IMStatus) => void): () => void;
// ── outbound ───────────────────────────────────────────────────────────────
- // 末位 opts.threadTs: thread 能力渠道(slack)把消息发进指定 thread;
- // 无 thread 概念的渠道(feishu)的实现可省略该参数(结构类型兼容), 调用方
- // 传了也只是被忽略。
+ // opts.threadTs identifies the reply root: Slack timestamp or Feishu private-topic root message id.
+ // Unsupported channels may omit it; Feishu group lanes retain their existing lane anchors.
/** 纯文本消息(不渲染 markdown 标记)。 */
sendText(
diff --git a/packages/lizi-im/src/feishu/__tests__/feishuOpenerConsume.test.ts b/packages/lizi-im/src/feishu/__tests__/feishuOpenerConsume.test.ts
index 7ab1eda29b..2dcf44d5fa 100644
--- a/packages/lizi-im/src/feishu/__tests__/feishuOpenerConsume.test.ts
+++ b/packages/lizi-im/src/feishu/__tests__/feishuOpenerConsume.test.ts
@@ -396,7 +396,7 @@ describe('FeishuIM opener consumption failure semantics', () => {
await expect(im.sendText('g/oc_c/omt_t', '/help')).resolves.toEqual({
messageId: 'om_help',
});
- expect(outboundMocks.sendText).toHaveBeenCalledWith('g/oc_c/omt_t', '/help');
+ expect(outboundMocks.sendText).toHaveBeenCalledWith('g/oc_c/omt_t', '/help', undefined);
await expect(sendOriginalFallback('g/oc_c/omt_t', '兜底')).resolves.toEqual({
messageId: 'om_done',
@@ -420,7 +420,7 @@ describe('FeishuIM opener consumption failure semantics', () => {
const helpP = im.sendText('g/oc_c/omt_t', '/help');
resolvePatch();
await expect(helpP).resolves.toEqual({ messageId: 'om_help' });
- expect(outboundMocks.sendText).toHaveBeenCalledWith('g/oc_c/omt_t', '/help');
+ expect(outboundMocks.sendText).toHaveBeenCalledWith('g/oc_c/omt_t', '/help', undefined);
});
it('保持连接时重新入队后按退避再排空, 不依赖下一次 connected', async () => {
diff --git a/packages/lizi-im/src/feishu/__tests__/outboundLane.test.ts b/packages/lizi-im/src/feishu/__tests__/outboundLane.test.ts
index 2b914dd1b0..f330064c1a 100644
--- a/packages/lizi-im/src/feishu/__tests__/outboundLane.test.ts
+++ b/packages/lizi-im/src/feishu/__tests__/outboundLane.test.ts
@@ -705,3 +705,28 @@ describe('feishu card lane registry', () => {
expect(outbound.resolveCardLane('om_replied', 'oc_group1')).toBeNull();
});
});
+
+describe('private notification topic output', () => {
+ beforeEach(() => { vi.clearAllMocks(); rebindFresh(); });
+
+ it('keeps text, interactive cards and streaming openers on the explicit topic root', async () => {
+ await outbound.sendText('ou_owner', 'first', { threadTs: 'om_notification_a' });
+ await outbound.sendInteractive('ou_owner', { body: 'approval', buttons: [] }, {
+ threadTs: 'om_notification_b', deliverToOwnerDm: true,
+ });
+ await outbound.sendCardRaw('ou_owner', { elements: [] }, { threadTs: 'om_notification_a' });
+ expect(larkMocks.reply.mock.calls.map(([p]) => p.path)).toEqual([
+ { message_id: 'om_notification_a' }, { message_id: 'om_notification_b' }, { message_id: 'om_notification_a' },
+ ]);
+ for (const [p] of larkMocks.reply.mock.calls) {
+ expect(p.data).toEqual(expect.objectContaining({ reply_in_thread: true }));
+ }
+ expect(larkMocks.create).not.toHaveBeenCalled();
+ });
+
+ it('rejects thread ids used as message ids without falling back to the main chat', async () => {
+ await expect(outbound.sendText('ou_owner', 'hello', { threadTs: 'omt_thread' })).rejects.toThrow();
+ expect(larkMocks.create).not.toHaveBeenCalled();
+ expect(larkMocks.reply).not.toHaveBeenCalled();
+ });
+});
diff --git a/packages/lizi-im/src/feishu/__tests__/streamingText.test.ts b/packages/lizi-im/src/feishu/__tests__/streamingText.test.ts
index ca377a3d2f..10e4156182 100644
--- a/packages/lizi-im/src/feishu/__tests__/streamingText.test.ts
+++ b/packages/lizi-im/src/feishu/__tests__/streamingText.test.ts
@@ -98,6 +98,7 @@ describe('feishu streaming text', () => {
expect(mocks.sendText).toHaveBeenCalledWith(
'ou_owner',
messages.streaming.deliveryFailed,
+ undefined,
);
});
diff --git a/packages/lizi-im/src/feishu/__tests__/wsClientGroup.test.ts b/packages/lizi-im/src/feishu/__tests__/wsClientGroup.test.ts
index c48b2f6ed3..9fb8697bf0 100644
--- a/packages/lizi-im/src/feishu/__tests__/wsClientGroup.test.ts
+++ b/packages/lizi-im/src/feishu/__tests__/wsClientGroup.test.ts
@@ -1341,3 +1341,29 @@ describe('feishu group inbound gate', () => {
expect(mocks.pushReplyAnchor).not.toHaveBeenCalled();
});
});
+
+describe('private topic notification ancestry', () => {
+ it('preserves root and thread separately while keeping the real owner identity', async () => {
+ await connect();
+ const events = collectEvents();
+ const raw = groupMessage({ rootId: 'om_notification', parentId: 'om_previous_reply', threadId: 'omt_topic' });
+ raw.message.chat_type = 'p2p';
+ await mocks.eventHandlers['im.message.receive_v1']!(raw);
+ expect(events).toHaveLength(1);
+ expect(events[0]).toMatchObject({
+ senderId: OWNER, chatId: 'oc_chat1',
+ replyThread: { rootMessageId: 'om_notification', threadId: 'omt_topic' },
+ });
+ expect(events[0].speaker).toBeUndefined();
+ });
+
+ it('does not treat an ordinary quoted reply without thread_id as a topic', async () => {
+ await connect();
+ const events = collectEvents();
+ const raw = groupMessage({ rootId: 'om_notification', parentId: 'om_notification' });
+ raw.message.chat_type = 'p2p';
+ await mocks.eventHandlers['im.message.receive_v1']!(raw);
+ expect(events).toHaveLength(1);
+ expect(events[0].replyThread).toBeUndefined();
+ });
+});
diff --git a/packages/lizi-im/src/feishu/index.ts b/packages/lizi-im/src/feishu/index.ts
index f50dac0b43..550466b4b4 100644
--- a/packages/lizi-im/src/feishu/index.ts
+++ b/packages/lizi-im/src/feishu/index.ts
@@ -395,6 +395,11 @@ export class FeishuIM extends BaseIM implements ChannelIM {
// ── outbound ────────────────────────────────────────────────────────────────
+ /** Send a notification and retain the provider receipt for host-side reply routing. */
+ sendNotification(userId: string, markdown: string): Promise<{ messageId: string; chatId?: string }> {
+ return outbound.sendNotification(userId, markdown);
+ }
+
async sendText(
userId: string,
text: string,
@@ -403,7 +408,7 @@ export class FeishuIM extends BaseIM implements ChannelIM {
return this.sendWithDeferredOpenerConsume(
userId,
'markdown',
- () => outbound.sendText(userId, text),
+ () => outbound.sendText(userId, text, opts),
opts?.fallbackOpenerId,
);
}
@@ -427,7 +432,7 @@ export class FeishuIM extends BaseIM implements ChannelIM {
return this.sendWithDeferredOpenerConsume(
userId,
'markdown',
- () => outbound.sendInteractive(userId, { body: markdown, buttons: [] }),
+ () => outbound.sendInteractive(userId, { body: markdown, buttons: [] }, opts),
opts?.fallbackOpenerId,
);
}
@@ -435,8 +440,9 @@ export class FeishuIM extends BaseIM implements ChannelIM {
startStreamingText(
userId: string,
initial?: string,
+ opts?: { threadTs?: string },
): Promise<StreamingTextHandle> {
- return streamingText.start(userId, initial);
+ return streamingText.start(userId, initial, opts);
}
/**
@@ -722,8 +728,8 @@ export class FeishuIM extends BaseIM implements ChannelIM {
return outbound.updateInteractive(messageId, spec);
}
- sendFile(userId: string, absPath: string, displayName?: string): Promise<SendFileResult> {
- return outbound.sendFile(userId, absPath, displayName);
+ sendFile(userId: string, absPath: string, displayName?: string, opts?: { threadTs?: string }): Promise<SendFileResult> {
+ return outbound.sendFile(userId, absPath, displayName, opts);
}
/**
diff --git a/packages/lizi-im/src/feishu/outbound.ts b/packages/lizi-im/src/feishu/outbound.ts
index 827661d1ce..659f77333c 100644
--- a/packages/lizi-im/src/feishu/outbound.ts
+++ b/packages/lizi-im/src/feishu/outbound.ts
@@ -616,8 +616,12 @@ type SendTarget =
* 不到, 以「流式建卡」为回合锚点领取点在本编排下成立: agent turn 恒以流式卡
* 开场, 一次性回复(slash 提示等)则一条消息领取一次。
*/
-function resolveSendTarget(userId: string, opts?: { advanceRound?: boolean }): SendTarget | null {
+function resolveSendTarget(userId: string, opts?: { advanceRound?: boolean; threadTs?: string }): SendTarget | null {
const lane = decodeLaneUserId(userId);
+ if (!lane && opts?.threadTs) {
+ if (!opts.threadTs.startsWith('om_')) throw new Error('Invalid Feishu reply message id');
+ return { kind: 'reply', messageId: opts.threadTs, replyInThread: true };
+ }
if (!lane) return { kind: 'open_id', id: userId };
const state = laneAnchors.get(userId) ?? {
@@ -658,7 +662,7 @@ async function createMessage(
msgType: string,
content: string,
uuid?: string,
-): Promise<{ messageId: string }> {
+): Promise<{ messageId: string; chatId?: string }> {
const c = ensureClient();
if (target.kind === 'reply') {
const res = await c.im.v1.message.reply({
@@ -680,10 +684,15 @@ async function createMessage(
});
const id = res.data?.message_id ?? '';
if (!id) throw new Error('[feishu/outbound] create: no message_id in response');
- return { messageId: id };
+ return { messageId: id, chatId: res.data?.chat_id };
}
-function requireSendTarget(userId: string, opts?: { advanceRound?: boolean }): SendTarget {
+/** Notification receipt used by the host to link replies to the originating session. */
+export async function sendNotification(userId: string, markdown: string): Promise<{ messageId: string; chatId?: string }> {
+ return createMessage({ kind: 'open_id', id: userId }, 'interactive', JSON.stringify(buildInteractiveCardV1({ body: markdown, buttons: [] })));
+}
+
+function requireSendTarget(userId: string, opts?: { advanceRound?: boolean; threadTs?: string }): SendTarget {
const target = resolveSendTarget(userId, opts);
if (!target) {
throw new Error(
@@ -740,8 +749,8 @@ function ensureClient(): Lark.Client {
// ── basic text ────────────────────────────────────────────────────────────────
-export async function sendText(userId: string, text: string): Promise<{ messageId: string }> {
- return createMessage(requireSendTarget(userId), 'text', JSON.stringify({ text }));
+export async function sendText(userId: string, text: string, opts?: { threadTs?: string }): Promise<{ messageId: string }> {
+ return createMessage(requireSendTarget(userId, opts), 'text', JSON.stringify({ text }));
}
/** 直接回复某条消息(非 owner 群 @ 的礼貌回应等 — 不走 lane 锚点)。 */
@@ -1113,7 +1122,7 @@ export function resolveCardLane(messageId: string, chatId: string): string | nul
export async function sendInteractive(
userId: string,
spec: InteractiveCardSpec,
- opts?: { deliverToOwnerDm?: boolean; ownerDmNote?: string },
+ opts?: { deliverToOwnerDm?: boolean; ownerDmNote?: string; threadTs?: string },
): Promise<{ messageId: string }> {
// 授权卡改投宿主私聊(群 lane 专用语义): 群里的授权卡只有 owner 能答且
// 消不掉。owner 未知时保持原 lane 投递, 不吞掉这次交互(telegram 同口径)。
@@ -1127,7 +1136,7 @@ export async function sendInteractive(
}
const card = buildInteractiveCardV1(spec);
const result = await createMessage(
- requireSendTarget(userId),
+ requireSendTarget(userId, opts),
'interactive',
JSON.stringify(card),
);
@@ -1170,9 +1179,10 @@ export async function patchCardRaw(messageId: string, cardJson: unknown): Promis
export async function sendCardRaw(
userId: string,
cardJson: unknown,
+ opts?: { threadTs?: string },
): Promise<{ messageId: string }> {
return createMessage(
- requireSendTarget(userId, { advanceRound: true }),
+ requireSendTarget(userId, { advanceRound: true, ...opts }),
'interactive',
JSON.stringify(cardJson),
);
@@ -1241,8 +1251,9 @@ export async function sendFile(
userId: string,
absPath: string,
displayName?: string,
+ opts?: { threadTs?: string },
): Promise<FeishuSendFileResult> {
- const target = resolveSendTarget(userId);
+ const target = resolveSendTarget(userId, opts);
if (!target) {
getLog().error(`[feishu/outbound] sendFile: no reply anchor for topic lane ...${userId.slice(-8)}`);
return { ok: false, reason: 'SEND_FAIL' };
diff --git a/packages/lizi-im/src/feishu/streamingText.ts b/packages/lizi-im/src/feishu/streamingText.ts
index e24b54c465..24b27af04e 100644
--- a/packages/lizi-im/src/feishu/streamingText.ts
+++ b/packages/lizi-im/src/feishu/streamingText.ts
@@ -117,7 +117,7 @@ class FeishuStreamingTextHandle implements StreamingTextHandle {
*/
private extraImageAbsPaths: string[] = [];
- constructor(messageId: string, openId: string, initial: string) {
+ constructor(messageId: string, openId: string, initial: string, private readonly opts?: { threadTs?: string }) {
this.messageId = messageId;
this.openId = openId;
// `initial` is what's currently DISPLAYED in feishu (e.g. "🧠 思考中...").
@@ -288,7 +288,7 @@ class FeishuStreamingTextHandle implements StreamingTextHandle {
await Promise.all(
fileLinks.map(async (link) => {
try {
- await sendFile(this.openId, link.absPath, link.alt || undefined);
+ await sendFile(this.openId, link.absPath, link.alt || undefined, this.opts);
} catch (err) {
const msg = err instanceof Error ? err.message : String(err);
log.warn(
@@ -340,7 +340,7 @@ class FeishuStreamingTextHandle implements StreamingTextHandle {
fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr);
log.warn(`[feishu/streamingText] fallback patch failed: ${fallbackMsg}`);
try {
- await sendText(this.openId, notice);
+ await sendText(this.openId, notice, this.opts);
} catch (textErr) {
const textMsg = textErr instanceof Error ? textErr.message : String(textErr);
log.error(`[feishu/streamingText] fallback text failed: ${textMsg}`);
@@ -353,15 +353,16 @@ class FeishuStreamingTextHandle implements StreamingTextHandle {
export async function start(
openId: string,
initial: string = transportMessages.streaming.randomThinking(),
+ opts?: { threadTs?: string },
): Promise<StreamingTextHandle> {
// 群主流 @ 开话题时, 开场白卡就是本轮流式卡(openThread 已用它开好话题) —
// 认领后直接 patch, 不再新建一条「开个话题」占位回复。
- const claimed = claimPatchableOpener(openId);
+ const claimed = opts?.threadTs ? null : claimPatchableOpener(openId);
if (claimed) {
- return new FeishuStreamingTextHandle(claimed, openId, initial);
+ return new FeishuStreamingTextHandle(claimed, openId, initial, opts);
}
- const { messageId } = await sendCardRaw(openId, buildMarkdownCardV2(initial));
- return new FeishuStreamingTextHandle(messageId, openId, initial);
+ const { messageId } = await sendCardRaw(openId, buildMarkdownCardV2(initial), opts);
+ return new FeishuStreamingTextHandle(messageId, openId, initial, opts);
}
/**
diff --git a/packages/lizi-im/src/feishu/wsClient.ts b/packages/lizi-im/src/feishu/wsClient.ts
index dccbaf9dba..5429f4118d 100644
--- a/packages/lizi-im/src/feishu/wsClient.ts
+++ b/packages/lizi-im/src/feishu/wsClient.ts
@@ -1826,6 +1826,9 @@ async function processClaimedMessage(
feishuEvents.emit('message', {
channelName: 'feishu',
senderId: laneUserId ?? senderOpenId,
+ ...(!isGroup && data.message?.thread_id && data.message?.root_id
+ ? { replyThread: { rootMessageId: data.message.root_id, threadId: data.message.thread_id } }
+ : {}),
chatId,
contextId: botAppId,
messageId,
diff --git a/packages/lizi-im/src/types.ts b/packages/lizi-im/src/types.ts
index 32f2e73439..28356a523c 100644
--- a/packages/lizi-im/src/types.ts
+++ b/packages/lizi-im/src/types.ts
@@ -231,6 +231,8 @@ export interface IMMessageEvent {
/** 被引消息的附件数(已并入本事件 attachments;0/缺省 = 无)。 */
attachmentCount?: number;
};
+ /** Native private topic metadata. Root message id and thread id are distinct. */
+ replyThread?: { rootMessageId: string; threadId: string };
/** Channel-specific raw event for debug. */
raw?: unknown;
/**
diff --git a/packages/lizi-mcps/src/__tests__/feishuBotChannelRouting.test.ts b/packages/lizi-mcps/src/__tests__/feishuBotChannelRouting.test.ts
index 1b512067a7..4c2b4fc400 100644
--- a/packages/lizi-mcps/src/__tests__/feishuBotChannelRouting.test.ts
+++ b/packages/lizi-mcps/src/__tests__/feishuBotChannelRouting.test.ts
@@ -138,3 +138,25 @@ describe('cindy_feishu_bot channel routing note', () => {
}
});
});
+
+
+describe('Feishu notification delivery result', () => {
+ it('reports delivered-but-unlinked as success with a no-resend warning and receipt', async () => {
+ const deps = makeDeps();
+ deps.sendMessage = vi.fn(async () => ({ ok: true, messageId: 'om_sent', sessionLinked: false }));
+ const harness = await makeHarness(deps);
+ try {
+ const result = await harness.client.callTool({
+ name: 'call_tool', arguments: { name: 'send_message_to_user', args: { text: 'done' } },
+ });
+ const content = result.content as Array<{ text?: string }>;
+ const payload = JSON.parse(content[0].text!);
+ expect(result.isError).not.toBe(true);
+ expect(payload).toMatchObject({ ok: true, messageId: 'om_sent', sessionLinked: false });
+ expect(payload.warning).toContain('不要重新发送');
+ expect(deps.sendMessage).toHaveBeenCalledTimes(1);
+ } finally {
+ await harness.cleanup();
+ }
+ });
+});
diff --git a/packages/lizi-mcps/src/__tests__/providersFeishuRouting.test.ts b/packages/lizi-mcps/src/__tests__/providersFeishuRouting.test.ts
new file mode 100644
index 0000000000..bab9d503d9
--- /dev/null
+++ b/packages/lizi-mcps/src/__tests__/providersFeishuRouting.test.ts
@@ -0,0 +1,43 @@
+import { describe, expect, it, vi } from 'vitest';
+import { createLiziMcpProviders } from '../providers.js';
+import { runWithLiziMcpSessionContext } from '../session-context.js';
+
+function setup() {
+ const sendMessage = vi.fn(async () => ({ ok: true, messageId: 'om_notification' }));
+ const provider = createLiziMcpProviders({
+ feishuBot: { getOwnerOpenId: () => 'ou_owner', sendFile: vi.fn(), sendMessage },
+ }).find((candidate) => candidate.name === 'cindy_feishu_bot')!;
+ const config = provider.toClaudeSdkConfig({ agentKind: 'codex', workingDir: '' }) as {
+ instance: { _registeredTools: Record<string, { handler: (args: unknown) => Promise<unknown> }> };
+ };
+ const call = () => config.instance._registeredTools.call_tool.handler({
+ name: 'send_message_to_user', args: { text: 'hello' },
+ });
+ return { sendMessage, call };
+}
+
+describe('Feishu notification session attribution', () => {
+ it('resolves each caller at tool-call time on the shared bridge', async () => {
+ const { sendMessage, call } = setup();
+ await Promise.all(['session-a', 'session-b'].map((sessionId) => runWithLiziMcpSessionContext(
+ { agentKind: 'codex', workingDir: '/tmp/task', sessionId }, call,
+ )));
+ expect(sendMessage).toHaveBeenCalledWith('ou_owner', 'hello', 'session-a');
+ expect(sendMessage).toHaveBeenCalledWith('ou_owner', 'hello', 'session-b');
+ });
+
+ it('keeps an explicit Feishu conversation out of owner notification routing', async () => {
+ const { sendMessage, call } = setup();
+ await runWithLiziMcpSessionContext({
+ agentKind: 'codex', workingDir: '/tmp/task', sessionId: 'group-session',
+ vendorOptions: { feishuChatId: 'oc_group' },
+ }, call);
+ expect(sendMessage).toHaveBeenCalledWith('oc_group', 'hello', undefined);
+ });
+
+ it('leaves messages unattributed when no trusted caller is available', async () => {
+ const { sendMessage, call } = setup();
+ await call();
+ expect(sendMessage).toHaveBeenCalledWith('ou_owner', 'hello', undefined);
+ });
+});
diff --git a/packages/lizi-mcps/src/cindy_feishuBotMcpServer.ts b/packages/lizi-mcps/src/cindy_feishuBotMcpServer.ts
index fb549c7223..44cbd549e2 100644
--- a/packages/lizi-mcps/src/cindy_feishuBotMcpServer.ts
+++ b/packages/lizi-mcps/src/cindy_feishuBotMcpServer.ts
@@ -270,6 +270,10 @@ function registerSendMessageToUser(
return buildJsonResult({
ok: true,
messageId: result.messageId,
+ ...(result.sessionLinked !== undefined ? { sessionLinked: result.sessionLinked } : {}),
+ ...(result.sessionLinked === false ? {
+ warning: '消息已发送,但回复关联保存失败;不要重新发送这条消息。请告知用户在 Cindy 原任务中继续。',
+ } : {}),
});
},
});
diff --git a/packages/lizi-mcps/src/providers.ts b/packages/lizi-mcps/src/providers.ts
index b41cb13bdc..98fa39a7eb 100644
--- a/packages/lizi-mcps/src/providers.ts
+++ b/packages/lizi-mcps/src/providers.ts
@@ -268,9 +268,15 @@ export function createLiziMcpProviders(
name: 'cindy_feishu_bot',
instance: createFeishuBotMcpServer({
getChatId: () =>
- readFeishuChatId(ctx) ?? opts.feishuBot!.getOwnerOpenId() ?? null,
+ readFeishuChatId(resolveLiziMcpSessionContext(ctx)) ?? opts.feishuBot!.getOwnerOpenId() ?? null,
sendFile: opts.feishuBot!.sendFile,
- sendMessage: opts.feishuBot!.sendMessage,
+ sendMessage: (chatId, text) => {
+ // Codex's shared bridge only has the calling session at tool-call time.
+ const current = resolveLiziMcpSessionContext(ctx);
+ return opts.feishuBot!.sendMessage(
+ chatId, text, readFeishuChatId(current) ? undefined : current.sessionId,
+ );
+ },
// slack-hook 会话里按来源在构建期注入渠道路由提示,
// 把「发给我」的默认通道钉死在会话自身渠道(规则 9)。
sessionSource: readSessionSource(ctx),
diff --git a/packages/lizi-mcps/src/types.ts b/packages/lizi-mcps/src/types.ts
index 17a4d42aa6..ecbc9bd975 100644
--- a/packages/lizi-mcps/src/types.ts
+++ b/packages/lizi-mcps/src/types.ts
@@ -93,6 +93,8 @@ export interface FeishuBotSendMessageResult {
ok: boolean;
/** Feishu message id on success. */
messageId?: string;
+ /** False means delivery succeeded but replies cannot resume the originating session. */
+ sessionLinked?: boolean;
/** Short reason on failure (e.g. 'SEND_FAIL', 'EMPTY_TEXT'). */
reason?: string;
}
@@ -114,6 +116,8 @@ export interface FeishuBotMcpHostDeps {
sendMessage(
chatId: string,
markdown: string,
+ /** Trusted calling session, only for notifications to the bot owner. */
+ notificationSessionId?: string,
): Promise<FeishuBotSendMessageResult>;
/**
* Return the bot's TOFU-recorded owner openId — i.e. the person who first