@vellumai/assistant 0.4.21 → 0.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scripts/ipc/check-swift-decoder-drift.ts +55 -44
- package/src/__tests__/__snapshots__/ipc-snapshot.test.ts.snap +0 -75
- package/src/__tests__/headless-browser-interactions.test.ts +0 -4
- package/src/__tests__/ipc-snapshot.test.ts +0 -54
- package/src/__tests__/resolve-guardian-trust-class.test.ts +61 -0
- package/src/__tests__/session-init.benchmark.test.ts +0 -4
- package/src/config/system-prompt.ts +1 -0
- package/src/config/templates/BOOTSTRAP.md +21 -31
- package/src/config/templates/SOUL.md +19 -9
- package/src/daemon/computer-use-session.ts +5 -3
- package/src/daemon/daemon-control.ts +3 -0
- package/src/daemon/handlers/browser.ts +2 -48
- package/src/daemon/handlers/config-voice.ts +155 -33
- package/src/daemon/handlers/dictation.ts +361 -214
- package/src/daemon/ipc-contract/browser.ts +4 -74
- package/src/daemon/ipc-contract/surfaces.ts +51 -48
- package/src/daemon/ipc-contract-inventory.json +0 -7
- package/src/daemon/session-agent-loop.ts +2 -1
- package/src/daemon/session-runtime-assembly.ts +477 -247
- package/src/daemon/session-surfaces.ts +5 -3
- package/src/daemon/session-tool-setup.ts +27 -13
- package/src/memory/migrations/102-alter-table-columns.ts +254 -37
- package/src/memory/schema.ts +1227 -1035
- package/src/tools/browser/browser-execution.ts +314 -331
- package/src/tools/browser/browser-handoff.ts +11 -37
- package/src/tools/browser/browser-manager.ts +271 -264
- package/src/tools/browser/browser-screencast.ts +19 -75
package/src/memory/schema.ts
CHANGED
|
@@ -1,304 +1,358 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
.notNull()
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
]
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
]
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
]
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
.notNull()
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
.notNull()
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
1
|
+
import {
|
|
2
|
+
blob,
|
|
3
|
+
index,
|
|
4
|
+
integer,
|
|
5
|
+
real,
|
|
6
|
+
sqliteTable,
|
|
7
|
+
text,
|
|
8
|
+
uniqueIndex,
|
|
9
|
+
} from "drizzle-orm/sqlite-core";
|
|
10
|
+
|
|
11
|
+
import { DAEMON_INTERNAL_ASSISTANT_ID } from "../runtime/assistant-scope.js";
|
|
12
|
+
|
|
13
|
+
export const conversations = sqliteTable(
|
|
14
|
+
"conversations",
|
|
15
|
+
{
|
|
16
|
+
id: text("id").primaryKey(),
|
|
17
|
+
title: text("title"),
|
|
18
|
+
createdAt: integer("created_at").notNull(),
|
|
19
|
+
updatedAt: integer("updated_at").notNull(),
|
|
20
|
+
totalInputTokens: integer("total_input_tokens").notNull().default(0),
|
|
21
|
+
totalOutputTokens: integer("total_output_tokens").notNull().default(0),
|
|
22
|
+
totalEstimatedCost: real("total_estimated_cost").notNull().default(0),
|
|
23
|
+
contextSummary: text("context_summary"),
|
|
24
|
+
contextCompactedMessageCount: integer("context_compacted_message_count")
|
|
25
|
+
.notNull()
|
|
26
|
+
.default(0),
|
|
27
|
+
contextCompactedAt: integer("context_compacted_at"),
|
|
28
|
+
threadType: text("thread_type").notNull().default("standard"),
|
|
29
|
+
source: text("source").notNull().default("user"),
|
|
30
|
+
memoryScopeId: text("memory_scope_id").notNull().default("default"),
|
|
31
|
+
originChannel: text("origin_channel"),
|
|
32
|
+
originInterface: text("origin_interface"),
|
|
33
|
+
isAutoTitle: integer("is_auto_title").notNull().default(1),
|
|
34
|
+
scheduleJobId: text("schedule_job_id"),
|
|
35
|
+
},
|
|
36
|
+
(table) => [
|
|
37
|
+
index("idx_conversations_updated_at").on(table.updatedAt),
|
|
38
|
+
index("idx_conversations_thread_type").on(table.threadType),
|
|
39
|
+
],
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const messages = sqliteTable(
|
|
43
|
+
"messages",
|
|
44
|
+
{
|
|
45
|
+
id: text("id").primaryKey(),
|
|
46
|
+
conversationId: text("conversation_id")
|
|
47
|
+
.notNull()
|
|
48
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
49
|
+
role: text("role").notNull(),
|
|
50
|
+
content: text("content").notNull(),
|
|
51
|
+
createdAt: integer("created_at").notNull(),
|
|
52
|
+
metadata: text("metadata"),
|
|
53
|
+
},
|
|
54
|
+
(table) => [index("idx_messages_conversation_id").on(table.conversationId)],
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const toolInvocations = sqliteTable(
|
|
58
|
+
"tool_invocations",
|
|
59
|
+
{
|
|
60
|
+
id: text("id").primaryKey(),
|
|
61
|
+
conversationId: text("conversation_id")
|
|
62
|
+
.notNull()
|
|
63
|
+
.references(() => conversations.id),
|
|
64
|
+
toolName: text("tool_name").notNull(),
|
|
65
|
+
input: text("input").notNull(),
|
|
66
|
+
result: text("result").notNull(),
|
|
67
|
+
decision: text("decision").notNull(),
|
|
68
|
+
riskLevel: text("risk_level").notNull(),
|
|
69
|
+
durationMs: integer("duration_ms").notNull(),
|
|
70
|
+
createdAt: integer("created_at").notNull(),
|
|
71
|
+
},
|
|
72
|
+
(table) => [
|
|
73
|
+
index("idx_tool_invocations_conversation_id").on(table.conversationId),
|
|
74
|
+
],
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
export const memorySegments = sqliteTable(
|
|
78
|
+
"memory_segments",
|
|
79
|
+
{
|
|
80
|
+
id: text("id").primaryKey(),
|
|
81
|
+
messageId: text("message_id")
|
|
82
|
+
.notNull()
|
|
83
|
+
.references(() => messages.id, { onDelete: "cascade" }),
|
|
84
|
+
conversationId: text("conversation_id")
|
|
85
|
+
.notNull()
|
|
86
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
87
|
+
role: text("role").notNull(),
|
|
88
|
+
segmentIndex: integer("segment_index").notNull(),
|
|
89
|
+
text: text("text").notNull(),
|
|
90
|
+
tokenEstimate: integer("token_estimate").notNull(),
|
|
91
|
+
scopeId: text("scope_id").notNull().default("default"),
|
|
92
|
+
contentHash: text("content_hash"),
|
|
93
|
+
createdAt: integer("created_at").notNull(),
|
|
94
|
+
updatedAt: integer("updated_at").notNull(),
|
|
95
|
+
},
|
|
96
|
+
(table) => [index("idx_memory_segments_scope_id").on(table.scopeId)],
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export const memoryItems = sqliteTable(
|
|
100
|
+
"memory_items",
|
|
101
|
+
{
|
|
102
|
+
id: text("id").primaryKey(),
|
|
103
|
+
kind: text("kind").notNull(),
|
|
104
|
+
subject: text("subject").notNull(),
|
|
105
|
+
statement: text("statement").notNull(),
|
|
106
|
+
status: text("status").notNull(),
|
|
107
|
+
confidence: real("confidence").notNull(),
|
|
108
|
+
importance: real("importance"),
|
|
109
|
+
accessCount: integer("access_count").notNull().default(0),
|
|
110
|
+
fingerprint: text("fingerprint").notNull(),
|
|
111
|
+
verificationState: text("verification_state")
|
|
112
|
+
.notNull()
|
|
113
|
+
.default("assistant_inferred"),
|
|
114
|
+
scopeId: text("scope_id").notNull().default("default"),
|
|
115
|
+
firstSeenAt: integer("first_seen_at").notNull(),
|
|
116
|
+
lastSeenAt: integer("last_seen_at").notNull(),
|
|
117
|
+
lastUsedAt: integer("last_used_at"),
|
|
118
|
+
validFrom: integer("valid_from"),
|
|
119
|
+
invalidAt: integer("invalid_at"),
|
|
120
|
+
},
|
|
121
|
+
(table) => [
|
|
122
|
+
index("idx_memory_items_scope_id").on(table.scopeId),
|
|
123
|
+
index("idx_memory_items_fingerprint").on(table.fingerprint),
|
|
124
|
+
],
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
export const memoryItemSources = sqliteTable(
|
|
128
|
+
"memory_item_sources",
|
|
129
|
+
{
|
|
130
|
+
memoryItemId: text("memory_item_id")
|
|
131
|
+
.notNull()
|
|
132
|
+
.references(() => memoryItems.id, { onDelete: "cascade" }),
|
|
133
|
+
messageId: text("message_id")
|
|
134
|
+
.notNull()
|
|
135
|
+
.references(() => messages.id, { onDelete: "cascade" }),
|
|
136
|
+
evidence: text("evidence"),
|
|
137
|
+
createdAt: integer("created_at").notNull(),
|
|
138
|
+
},
|
|
139
|
+
(table) => [
|
|
140
|
+
index("idx_memory_item_sources_memory_item_id").on(table.memoryItemId),
|
|
141
|
+
],
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
export const memoryItemConflicts = sqliteTable(
|
|
145
|
+
"memory_item_conflicts",
|
|
146
|
+
{
|
|
147
|
+
id: text("id").primaryKey(),
|
|
148
|
+
scopeId: text("scope_id").notNull().default("default"),
|
|
149
|
+
existingItemId: text("existing_item_id")
|
|
150
|
+
.notNull()
|
|
151
|
+
.references(() => memoryItems.id, { onDelete: "cascade" }),
|
|
152
|
+
candidateItemId: text("candidate_item_id")
|
|
153
|
+
.notNull()
|
|
154
|
+
.references(() => memoryItems.id, { onDelete: "cascade" }),
|
|
155
|
+
relationship: text("relationship").notNull(),
|
|
156
|
+
status: text("status").notNull(),
|
|
157
|
+
clarificationQuestion: text("clarification_question"),
|
|
158
|
+
resolutionNote: text("resolution_note"),
|
|
159
|
+
lastAskedAt: integer("last_asked_at"),
|
|
160
|
+
resolvedAt: integer("resolved_at"),
|
|
161
|
+
createdAt: integer("created_at").notNull(),
|
|
162
|
+
updatedAt: integer("updated_at").notNull(),
|
|
163
|
+
},
|
|
164
|
+
(table) => [index("idx_memory_item_conflicts_scope_id").on(table.scopeId)],
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
export const memorySummaries = sqliteTable(
|
|
168
|
+
"memory_summaries",
|
|
169
|
+
{
|
|
170
|
+
id: text("id").primaryKey(),
|
|
171
|
+
scope: text("scope").notNull(),
|
|
172
|
+
scopeKey: text("scope_key").notNull(),
|
|
173
|
+
summary: text("summary").notNull(),
|
|
174
|
+
tokenEstimate: integer("token_estimate").notNull(),
|
|
175
|
+
version: integer("version").notNull().default(1),
|
|
176
|
+
scopeId: text("scope_id").notNull().default("default"),
|
|
177
|
+
startAt: integer("start_at").notNull(),
|
|
178
|
+
endAt: integer("end_at").notNull(),
|
|
179
|
+
createdAt: integer("created_at").notNull(),
|
|
180
|
+
updatedAt: integer("updated_at").notNull(),
|
|
181
|
+
},
|
|
182
|
+
(table) => [
|
|
183
|
+
index("idx_memory_summaries_scope_id").on(table.scopeId),
|
|
184
|
+
uniqueIndex("idx_memory_summaries_scope_scope_key").on(
|
|
185
|
+
table.scope,
|
|
186
|
+
table.scopeKey,
|
|
187
|
+
),
|
|
188
|
+
],
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
export const memoryEmbeddings = sqliteTable(
|
|
192
|
+
"memory_embeddings",
|
|
193
|
+
{
|
|
194
|
+
id: text("id").primaryKey(),
|
|
195
|
+
targetType: text("target_type").notNull(),
|
|
196
|
+
targetId: text("target_id").notNull(),
|
|
197
|
+
provider: text("provider").notNull(),
|
|
198
|
+
model: text("model").notNull(),
|
|
199
|
+
dimensions: integer("dimensions").notNull(),
|
|
200
|
+
vectorJson: text("vector_json"),
|
|
201
|
+
vectorBlob: blob("vector_blob"),
|
|
202
|
+
contentHash: text("content_hash"),
|
|
203
|
+
createdAt: integer("created_at").notNull(),
|
|
204
|
+
updatedAt: integer("updated_at").notNull(),
|
|
205
|
+
},
|
|
206
|
+
(table) => [
|
|
207
|
+
uniqueIndex("idx_memory_embeddings_target_provider_model").on(
|
|
208
|
+
table.targetType,
|
|
209
|
+
table.targetId,
|
|
210
|
+
table.provider,
|
|
211
|
+
table.model,
|
|
212
|
+
),
|
|
213
|
+
],
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
export const memoryJobs = sqliteTable("memory_jobs", {
|
|
217
|
+
id: text("id").primaryKey(),
|
|
218
|
+
type: text("type").notNull(),
|
|
219
|
+
payload: text("payload").notNull(),
|
|
220
|
+
status: text("status").notNull(),
|
|
221
|
+
attempts: integer("attempts").notNull().default(0),
|
|
222
|
+
deferrals: integer("deferrals").notNull().default(0),
|
|
223
|
+
runAfter: integer("run_after").notNull(),
|
|
224
|
+
lastError: text("last_error"),
|
|
225
|
+
startedAt: integer("started_at"),
|
|
226
|
+
createdAt: integer("created_at").notNull(),
|
|
227
|
+
updatedAt: integer("updated_at").notNull(),
|
|
177
228
|
});
|
|
178
229
|
|
|
179
|
-
export const conversationKeys = sqliteTable(
|
|
180
|
-
id: text(
|
|
181
|
-
conversationKey: text(
|
|
182
|
-
conversationId: text(
|
|
230
|
+
export const conversationKeys = sqliteTable("conversation_keys", {
|
|
231
|
+
id: text("id").primaryKey(),
|
|
232
|
+
conversationKey: text("conversation_key").notNull(),
|
|
233
|
+
conversationId: text("conversation_id")
|
|
183
234
|
.notNull()
|
|
184
|
-
.references(() => conversations.id, { onDelete:
|
|
185
|
-
createdAt: integer(
|
|
235
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
236
|
+
createdAt: integer("created_at").notNull(),
|
|
186
237
|
});
|
|
187
238
|
|
|
188
|
-
export const attachments = sqliteTable(
|
|
189
|
-
id: text(
|
|
190
|
-
originalFilename: text(
|
|
191
|
-
mimeType: text(
|
|
192
|
-
sizeBytes: integer(
|
|
193
|
-
kind: text(
|
|
194
|
-
dataBase64: text(
|
|
195
|
-
contentHash: text(
|
|
196
|
-
thumbnailBase64: text(
|
|
197
|
-
createdAt: integer(
|
|
239
|
+
export const attachments = sqliteTable("attachments", {
|
|
240
|
+
id: text("id").primaryKey(),
|
|
241
|
+
originalFilename: text("original_filename").notNull(),
|
|
242
|
+
mimeType: text("mime_type").notNull(),
|
|
243
|
+
sizeBytes: integer("size_bytes").notNull(),
|
|
244
|
+
kind: text("kind").notNull(),
|
|
245
|
+
dataBase64: text("data_base64").notNull(),
|
|
246
|
+
contentHash: text("content_hash"),
|
|
247
|
+
thumbnailBase64: text("thumbnail_base64"),
|
|
248
|
+
createdAt: integer("created_at").notNull(),
|
|
198
249
|
});
|
|
199
250
|
|
|
200
|
-
export const messageAttachments = sqliteTable(
|
|
201
|
-
id: text(
|
|
202
|
-
messageId: text(
|
|
251
|
+
export const messageAttachments = sqliteTable("message_attachments", {
|
|
252
|
+
id: text("id").primaryKey(),
|
|
253
|
+
messageId: text("message_id")
|
|
203
254
|
.notNull()
|
|
204
|
-
.references(() => messages.id, { onDelete:
|
|
205
|
-
attachmentId: text(
|
|
255
|
+
.references(() => messages.id, { onDelete: "cascade" }),
|
|
256
|
+
attachmentId: text("attachment_id")
|
|
206
257
|
.notNull()
|
|
207
|
-
.references(() => attachments.id, { onDelete:
|
|
208
|
-
position: integer(
|
|
209
|
-
createdAt: integer(
|
|
258
|
+
.references(() => attachments.id, { onDelete: "cascade" }),
|
|
259
|
+
position: integer("position").notNull().default(0),
|
|
260
|
+
createdAt: integer("created_at").notNull(),
|
|
210
261
|
});
|
|
211
262
|
|
|
212
|
-
export const channelInboundEvents = sqliteTable(
|
|
213
|
-
id: text(
|
|
214
|
-
sourceChannel: text(
|
|
215
|
-
externalChatId: text(
|
|
216
|
-
externalMessageId: text(
|
|
217
|
-
sourceMessageId: text(
|
|
218
|
-
conversationId: text(
|
|
263
|
+
export const channelInboundEvents = sqliteTable("channel_inbound_events", {
|
|
264
|
+
id: text("id").primaryKey(),
|
|
265
|
+
sourceChannel: text("source_channel").notNull(),
|
|
266
|
+
externalChatId: text("external_chat_id").notNull(),
|
|
267
|
+
externalMessageId: text("external_message_id").notNull(),
|
|
268
|
+
sourceMessageId: text("source_message_id"),
|
|
269
|
+
conversationId: text("conversation_id")
|
|
219
270
|
.notNull()
|
|
220
|
-
.references(() => conversations.id, { onDelete:
|
|
221
|
-
messageId: text(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
271
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
272
|
+
messageId: text("message_id").references(() => messages.id, {
|
|
273
|
+
onDelete: "cascade",
|
|
274
|
+
}),
|
|
275
|
+
deliveryStatus: text("delivery_status").notNull().default("pending"),
|
|
276
|
+
processingStatus: text("processing_status").notNull().default("pending"),
|
|
277
|
+
processingAttempts: integer("processing_attempts").notNull().default(0),
|
|
278
|
+
lastProcessingError: text("last_processing_error"),
|
|
279
|
+
retryAfter: integer("retry_after"),
|
|
280
|
+
rawPayload: text("raw_payload"),
|
|
281
|
+
deliveredSegmentCount: integer("delivered_segment_count")
|
|
282
|
+
.notNull()
|
|
283
|
+
.default(0),
|
|
284
|
+
createdAt: integer("created_at").notNull(),
|
|
285
|
+
updatedAt: integer("updated_at").notNull(),
|
|
232
286
|
});
|
|
233
287
|
|
|
234
|
-
export const memoryCheckpoints = sqliteTable(
|
|
235
|
-
key: text(
|
|
236
|
-
value: text(
|
|
237
|
-
updatedAt: integer(
|
|
288
|
+
export const memoryCheckpoints = sqliteTable("memory_checkpoints", {
|
|
289
|
+
key: text("key").primaryKey(),
|
|
290
|
+
value: text("value").notNull(),
|
|
291
|
+
updatedAt: integer("updated_at").notNull(),
|
|
238
292
|
});
|
|
239
293
|
|
|
240
294
|
// ── Reminders ────────────────────────────────────────────────────────
|
|
241
295
|
|
|
242
|
-
export const reminders = sqliteTable(
|
|
243
|
-
id: text(
|
|
244
|
-
label: text(
|
|
245
|
-
message: text(
|
|
246
|
-
fireAt: integer(
|
|
247
|
-
mode: text(
|
|
248
|
-
status: text(
|
|
249
|
-
firedAt: integer(
|
|
250
|
-
conversationId: text(
|
|
251
|
-
routingIntent: text(
|
|
252
|
-
routingHintsJson: text(
|
|
253
|
-
createdAt: integer(
|
|
254
|
-
updatedAt: integer(
|
|
296
|
+
export const reminders = sqliteTable("reminders", {
|
|
297
|
+
id: text("id").primaryKey(),
|
|
298
|
+
label: text("label").notNull(),
|
|
299
|
+
message: text("message").notNull(),
|
|
300
|
+
fireAt: integer("fire_at").notNull(), // epoch ms, absolute timestamp
|
|
301
|
+
mode: text("mode").notNull(), // 'notify' | 'execute'
|
|
302
|
+
status: text("status").notNull(), // 'pending' | 'firing' | 'fired' | 'cancelled'
|
|
303
|
+
firedAt: integer("fired_at"),
|
|
304
|
+
conversationId: text("conversation_id"),
|
|
305
|
+
routingIntent: text("routing_intent").notNull().default("all_channels"), // 'single_channel' | 'multi_channel' | 'all_channels'
|
|
306
|
+
routingHintsJson: text("routing_hints_json").notNull().default("{}"),
|
|
307
|
+
createdAt: integer("created_at").notNull(),
|
|
308
|
+
updatedAt: integer("updated_at").notNull(),
|
|
255
309
|
});
|
|
256
310
|
|
|
257
311
|
// ── Recurrence Schedules ─────────────────────────────────────────────
|
|
258
312
|
|
|
259
|
-
export const cronJobs = sqliteTable(
|
|
260
|
-
id: text(
|
|
261
|
-
name: text(
|
|
262
|
-
enabled: integer(
|
|
263
|
-
cronExpression: text(
|
|
264
|
-
scheduleSyntax: text(
|
|
265
|
-
timezone: text(
|
|
266
|
-
message: text(
|
|
267
|
-
nextRunAt: integer(
|
|
268
|
-
lastRunAt: integer(
|
|
269
|
-
lastStatus: text(
|
|
270
|
-
retryCount: integer(
|
|
271
|
-
createdBy: text(
|
|
272
|
-
createdAt: integer(
|
|
273
|
-
updatedAt: integer(
|
|
313
|
+
export const cronJobs = sqliteTable("cron_jobs", {
|
|
314
|
+
id: text("id").primaryKey(),
|
|
315
|
+
name: text("name").notNull(),
|
|
316
|
+
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
|
|
317
|
+
cronExpression: text("cron_expression").notNull(), // e.g. '0 9 * * 1-5'
|
|
318
|
+
scheduleSyntax: text("schedule_syntax").notNull().default("cron"), // 'cron' | 'rrule'
|
|
319
|
+
timezone: text("timezone"), // e.g. 'America/Los_Angeles'
|
|
320
|
+
message: text("message").notNull(),
|
|
321
|
+
nextRunAt: integer("next_run_at").notNull(),
|
|
322
|
+
lastRunAt: integer("last_run_at"),
|
|
323
|
+
lastStatus: text("last_status"), // 'ok' | 'error'
|
|
324
|
+
retryCount: integer("retry_count").notNull().default(0),
|
|
325
|
+
createdBy: text("created_by").notNull(), // 'agent' | 'user'
|
|
326
|
+
createdAt: integer("created_at").notNull(),
|
|
327
|
+
updatedAt: integer("updated_at").notNull(),
|
|
274
328
|
});
|
|
275
329
|
|
|
276
|
-
export const accounts = sqliteTable(
|
|
277
|
-
id: text(
|
|
278
|
-
service: text(
|
|
279
|
-
username: text(
|
|
280
|
-
email: text(
|
|
281
|
-
displayName: text(
|
|
282
|
-
status: text(
|
|
283
|
-
credentialRef: text(
|
|
284
|
-
metadataJson: text(
|
|
285
|
-
createdAt: integer(
|
|
286
|
-
updatedAt: integer(
|
|
330
|
+
export const accounts = sqliteTable("accounts", {
|
|
331
|
+
id: text("id").primaryKey(),
|
|
332
|
+
service: text("service").notNull(),
|
|
333
|
+
username: text("username"),
|
|
334
|
+
email: text("email"),
|
|
335
|
+
displayName: text("display_name"),
|
|
336
|
+
status: text("status").notNull().default("active"),
|
|
337
|
+
credentialRef: text("credential_ref"),
|
|
338
|
+
metadataJson: text("metadata_json"),
|
|
339
|
+
createdAt: integer("created_at").notNull(),
|
|
340
|
+
updatedAt: integer("updated_at").notNull(),
|
|
287
341
|
});
|
|
288
342
|
|
|
289
|
-
export const cronRuns = sqliteTable(
|
|
290
|
-
id: text(
|
|
291
|
-
jobId: text(
|
|
343
|
+
export const cronRuns = sqliteTable("cron_runs", {
|
|
344
|
+
id: text("id").primaryKey(),
|
|
345
|
+
jobId: text("job_id")
|
|
292
346
|
.notNull()
|
|
293
|
-
.references(() => cronJobs.id, { onDelete:
|
|
294
|
-
status: text(
|
|
295
|
-
startedAt: integer(
|
|
296
|
-
finishedAt: integer(
|
|
297
|
-
durationMs: integer(
|
|
298
|
-
output: text(
|
|
299
|
-
error: text(
|
|
300
|
-
conversationId: text(
|
|
301
|
-
createdAt: integer(
|
|
347
|
+
.references(() => cronJobs.id, { onDelete: "cascade" }),
|
|
348
|
+
status: text("status").notNull(), // 'ok' | 'error'
|
|
349
|
+
startedAt: integer("started_at").notNull(),
|
|
350
|
+
finishedAt: integer("finished_at"),
|
|
351
|
+
durationMs: integer("duration_ms"),
|
|
352
|
+
output: text("output"),
|
|
353
|
+
error: text("error"),
|
|
354
|
+
conversationId: text("conversation_id"),
|
|
355
|
+
createdAt: integer("created_at").notNull(),
|
|
302
356
|
});
|
|
303
357
|
|
|
304
358
|
// Recurrence-centric aliases — prefer these in new code.
|
|
@@ -310,901 +364,1039 @@ export const scheduleRuns = cronRuns;
|
|
|
310
364
|
|
|
311
365
|
// ── Entity Graph ─────────────────────────────────────────────────────
|
|
312
366
|
|
|
313
|
-
export const memoryEntities = sqliteTable(
|
|
314
|
-
id: text(
|
|
315
|
-
name: text(
|
|
316
|
-
type: text(
|
|
317
|
-
aliases: text(
|
|
318
|
-
description: text(
|
|
319
|
-
firstSeenAt: integer(
|
|
320
|
-
lastSeenAt: integer(
|
|
321
|
-
mentionCount: integer(
|
|
367
|
+
export const memoryEntities = sqliteTable("memory_entities", {
|
|
368
|
+
id: text("id").primaryKey(),
|
|
369
|
+
name: text("name").notNull(),
|
|
370
|
+
type: text("type").notNull(),
|
|
371
|
+
aliases: text("aliases"),
|
|
372
|
+
description: text("description"),
|
|
373
|
+
firstSeenAt: integer("first_seen_at").notNull(),
|
|
374
|
+
lastSeenAt: integer("last_seen_at").notNull(),
|
|
375
|
+
mentionCount: integer("mention_count").notNull().default(1),
|
|
322
376
|
});
|
|
323
377
|
|
|
324
|
-
export const memoryEntityRelations = sqliteTable(
|
|
325
|
-
id: text(
|
|
326
|
-
sourceEntityId: text(
|
|
327
|
-
targetEntityId: text(
|
|
328
|
-
relation: text(
|
|
329
|
-
evidence: text(
|
|
330
|
-
firstSeenAt: integer(
|
|
331
|
-
lastSeenAt: integer(
|
|
378
|
+
export const memoryEntityRelations = sqliteTable("memory_entity_relations", {
|
|
379
|
+
id: text("id").primaryKey(),
|
|
380
|
+
sourceEntityId: text("source_entity_id").notNull(),
|
|
381
|
+
targetEntityId: text("target_entity_id").notNull(),
|
|
382
|
+
relation: text("relation").notNull(),
|
|
383
|
+
evidence: text("evidence"),
|
|
384
|
+
firstSeenAt: integer("first_seen_at").notNull(),
|
|
385
|
+
lastSeenAt: integer("last_seen_at").notNull(),
|
|
332
386
|
});
|
|
333
387
|
|
|
334
|
-
export const memoryItemEntities = sqliteTable(
|
|
335
|
-
memoryItemId: text(
|
|
336
|
-
entityId: text(
|
|
388
|
+
export const memoryItemEntities = sqliteTable("memory_item_entities", {
|
|
389
|
+
memoryItemId: text("memory_item_id").notNull(),
|
|
390
|
+
entityId: text("entity_id").notNull(),
|
|
337
391
|
});
|
|
338
392
|
|
|
339
|
-
export const sharedAppLinks = sqliteTable(
|
|
340
|
-
id: text(
|
|
341
|
-
shareToken: text(
|
|
342
|
-
bundleData: blob(
|
|
343
|
-
bundleSizeBytes: integer(
|
|
344
|
-
manifestJson: text(
|
|
345
|
-
downloadCount: integer(
|
|
346
|
-
createdAt: integer(
|
|
347
|
-
expiresAt: integer(
|
|
393
|
+
export const sharedAppLinks = sqliteTable("shared_app_links", {
|
|
394
|
+
id: text("id").primaryKey(),
|
|
395
|
+
shareToken: text("share_token").notNull().unique(),
|
|
396
|
+
bundleData: blob("bundle_data", { mode: "buffer" }).notNull(),
|
|
397
|
+
bundleSizeBytes: integer("bundle_size_bytes").notNull(),
|
|
398
|
+
manifestJson: text("manifest_json").notNull(),
|
|
399
|
+
downloadCount: integer("download_count").notNull().default(0),
|
|
400
|
+
createdAt: integer("created_at").notNull(),
|
|
401
|
+
expiresAt: integer("expires_at"),
|
|
348
402
|
});
|
|
349
403
|
|
|
350
404
|
// ── Contacts ─────────────────────────────────────────────────────────
|
|
351
405
|
|
|
352
|
-
export const contacts = sqliteTable(
|
|
353
|
-
id: text(
|
|
354
|
-
displayName: text(
|
|
355
|
-
relationship: text(
|
|
356
|
-
importance: real(
|
|
357
|
-
responseExpectation: text(
|
|
358
|
-
preferredTone: text(
|
|
359
|
-
lastInteraction: integer(
|
|
360
|
-
interactionCount: integer(
|
|
361
|
-
createdAt: integer(
|
|
362
|
-
updatedAt: integer(
|
|
406
|
+
export const contacts = sqliteTable("contacts", {
|
|
407
|
+
id: text("id").primaryKey(),
|
|
408
|
+
displayName: text("display_name").notNull(),
|
|
409
|
+
relationship: text("relationship"), // e.g. 'colleague', 'friend', 'manager', 'client'
|
|
410
|
+
importance: real("importance").notNull().default(0.5), // 0-1 scale, learned from interaction patterns
|
|
411
|
+
responseExpectation: text("response_expectation"), // e.g. 'immediate', 'within_hours', 'casual'
|
|
412
|
+
preferredTone: text("preferred_tone"), // e.g. 'formal', 'casual', 'friendly'
|
|
413
|
+
lastInteraction: integer("last_interaction"), // epoch ms
|
|
414
|
+
interactionCount: integer("interaction_count").notNull().default(0),
|
|
415
|
+
createdAt: integer("created_at").notNull(),
|
|
416
|
+
updatedAt: integer("updated_at").notNull(),
|
|
363
417
|
});
|
|
364
418
|
|
|
365
|
-
export const contactChannels = sqliteTable(
|
|
366
|
-
id: text(
|
|
367
|
-
contactId: text(
|
|
419
|
+
export const contactChannels = sqliteTable("contact_channels", {
|
|
420
|
+
id: text("id").primaryKey(),
|
|
421
|
+
contactId: text("contact_id")
|
|
422
|
+
.notNull()
|
|
423
|
+
.references(() => contacts.id, { onDelete: "cascade" }),
|
|
424
|
+
type: text("type").notNull(), // 'email', 'slack', 'whatsapp', 'phone', etc.
|
|
425
|
+
address: text("address").notNull(), // the actual identifier on that channel
|
|
426
|
+
isPrimary: integer("is_primary", { mode: "boolean" })
|
|
368
427
|
.notNull()
|
|
369
|
-
.
|
|
370
|
-
|
|
371
|
-
address: text('address').notNull(), // the actual identifier on that channel
|
|
372
|
-
isPrimary: integer('is_primary', { mode: 'boolean' }).notNull().default(false),
|
|
373
|
-
createdAt: integer('created_at').notNull(),
|
|
428
|
+
.default(false),
|
|
429
|
+
createdAt: integer("created_at").notNull(),
|
|
374
430
|
});
|
|
375
431
|
|
|
376
432
|
// ── Triage Results ───────────────────────────────────────────────────
|
|
377
433
|
|
|
378
|
-
export const triageResults = sqliteTable(
|
|
379
|
-
id: text(
|
|
380
|
-
channel: text(
|
|
381
|
-
sender: text(
|
|
382
|
-
category: text(
|
|
383
|
-
confidence: real(
|
|
384
|
-
suggestedAction: text(
|
|
385
|
-
matchedPlaybookIds: text(
|
|
386
|
-
messageId: text(
|
|
387
|
-
createdAt: integer(
|
|
434
|
+
export const triageResults = sqliteTable("triage_results", {
|
|
435
|
+
id: text("id").primaryKey(),
|
|
436
|
+
channel: text("channel").notNull(),
|
|
437
|
+
sender: text("sender").notNull(),
|
|
438
|
+
category: text("category").notNull(),
|
|
439
|
+
confidence: real("confidence").notNull(),
|
|
440
|
+
suggestedAction: text("suggested_action").notNull(),
|
|
441
|
+
matchedPlaybookIds: text("matched_playbook_ids"), // JSON array of playbook memory item IDs
|
|
442
|
+
messageId: text("message_id"), // optional external message identifier
|
|
443
|
+
createdAt: integer("created_at").notNull(),
|
|
388
444
|
});
|
|
389
445
|
|
|
390
446
|
// ── Follow-ups ──────────────────────────────────────────────────────
|
|
391
447
|
|
|
392
|
-
export const followups = sqliteTable(
|
|
393
|
-
id: text(
|
|
394
|
-
channel: text(
|
|
395
|
-
threadId: text(
|
|
396
|
-
contactId: text(
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
448
|
+
export const followups = sqliteTable("followups", {
|
|
449
|
+
id: text("id").primaryKey(),
|
|
450
|
+
channel: text("channel").notNull(), // 'email', 'slack', 'whatsapp', etc.
|
|
451
|
+
threadId: text("thread_id").notNull(), // external thread/conversation identifier
|
|
452
|
+
contactId: text("contact_id").references(() => contacts.id, {
|
|
453
|
+
onDelete: "set null",
|
|
454
|
+
}),
|
|
455
|
+
sentAt: integer("sent_at").notNull(), // epoch ms — when the outbound message was sent
|
|
456
|
+
expectedResponseBy: integer("expected_response_by"), // epoch ms — deadline for expected reply
|
|
457
|
+
status: text("status").notNull().default("pending"), // 'pending' | 'resolved' | 'overdue' | 'nudged'
|
|
458
|
+
reminderCronId: text("reminder_cron_id"), // optional cron job ID for reminder
|
|
459
|
+
createdAt: integer("created_at").notNull(),
|
|
460
|
+
updatedAt: integer("updated_at").notNull(),
|
|
404
461
|
});
|
|
405
462
|
|
|
406
463
|
// ── Tasks ────────────────────────────────────────────────────────────
|
|
407
464
|
|
|
408
|
-
export const tasks = sqliteTable(
|
|
409
|
-
id: text(
|
|
410
|
-
title: text(
|
|
411
|
-
template: text(
|
|
412
|
-
inputSchema: text(
|
|
413
|
-
contextFlags: text(
|
|
414
|
-
requiredTools: text(
|
|
415
|
-
createdFromConversationId: text(
|
|
416
|
-
status: text(
|
|
417
|
-
createdAt: integer(
|
|
418
|
-
updatedAt: integer(
|
|
465
|
+
export const tasks = sqliteTable("tasks", {
|
|
466
|
+
id: text("id").primaryKey(),
|
|
467
|
+
title: text("title").notNull(),
|
|
468
|
+
template: text("template").notNull(),
|
|
469
|
+
inputSchema: text("input_schema"),
|
|
470
|
+
contextFlags: text("context_flags"),
|
|
471
|
+
requiredTools: text("required_tools"),
|
|
472
|
+
createdFromConversationId: text("created_from_conversation_id"),
|
|
473
|
+
status: text("status").notNull().default("active"),
|
|
474
|
+
createdAt: integer("created_at").notNull(),
|
|
475
|
+
updatedAt: integer("updated_at").notNull(),
|
|
419
476
|
});
|
|
420
477
|
|
|
421
|
-
export const taskRuns = sqliteTable(
|
|
422
|
-
id: text(
|
|
423
|
-
taskId: text(
|
|
478
|
+
export const taskRuns = sqliteTable("task_runs", {
|
|
479
|
+
id: text("id").primaryKey(),
|
|
480
|
+
taskId: text("task_id")
|
|
424
481
|
.notNull()
|
|
425
|
-
.references(() => tasks.id, { onDelete:
|
|
426
|
-
conversationId: text(
|
|
427
|
-
status: text(
|
|
428
|
-
startedAt: integer(
|
|
429
|
-
finishedAt: integer(
|
|
430
|
-
error: text(
|
|
431
|
-
principalId: text(
|
|
432
|
-
memoryScopeId: text(
|
|
433
|
-
createdAt: integer(
|
|
482
|
+
.references(() => tasks.id, { onDelete: "cascade" }),
|
|
483
|
+
conversationId: text("conversation_id"),
|
|
484
|
+
status: text("status").notNull().default("pending"),
|
|
485
|
+
startedAt: integer("started_at"),
|
|
486
|
+
finishedAt: integer("finished_at"),
|
|
487
|
+
error: text("error"),
|
|
488
|
+
principalId: text("principal_id"),
|
|
489
|
+
memoryScopeId: text("memory_scope_id"),
|
|
490
|
+
createdAt: integer("created_at").notNull(),
|
|
434
491
|
});
|
|
435
492
|
|
|
436
|
-
export const taskCandidates = sqliteTable(
|
|
437
|
-
id: text(
|
|
438
|
-
sourceConversationId: text(
|
|
439
|
-
compiledTemplate: text(
|
|
440
|
-
confidence: real(
|
|
441
|
-
requiredTools: text(
|
|
442
|
-
createdAt: integer(
|
|
443
|
-
promotedTaskId: text(
|
|
493
|
+
export const taskCandidates = sqliteTable("task_candidates", {
|
|
494
|
+
id: text("id").primaryKey(),
|
|
495
|
+
sourceConversationId: text("source_conversation_id").notNull(),
|
|
496
|
+
compiledTemplate: text("compiled_template").notNull(),
|
|
497
|
+
confidence: real("confidence"),
|
|
498
|
+
requiredTools: text("required_tools"), // JSON array string
|
|
499
|
+
createdAt: integer("created_at").notNull(),
|
|
500
|
+
promotedTaskId: text("promoted_task_id"), // set when candidate is promoted to a real task
|
|
444
501
|
});
|
|
445
502
|
|
|
446
503
|
// ── Work Items (Tasks) ───────────────────────────────────────────────
|
|
447
504
|
|
|
448
|
-
export const workItems = sqliteTable(
|
|
449
|
-
id: text(
|
|
450
|
-
taskId: text(
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
505
|
+
export const workItems = sqliteTable("work_items", {
|
|
506
|
+
id: text("id").primaryKey(),
|
|
507
|
+
taskId: text("task_id")
|
|
508
|
+
.notNull()
|
|
509
|
+
.references(() => tasks.id),
|
|
510
|
+
title: text("title").notNull(),
|
|
511
|
+
notes: text("notes"),
|
|
512
|
+
status: text("status").notNull().default("queued"), // queued | running | awaiting_review | failed | cancelled | done | archived
|
|
513
|
+
priorityTier: integer("priority_tier").notNull().default(1), // 0=high, 1=medium, 2=low
|
|
514
|
+
sortIndex: integer("sort_index"), // manual ordering within same priority tier; null = fall back to updated_at
|
|
515
|
+
lastRunId: text("last_run_id"),
|
|
516
|
+
lastRunConversationId: text("last_run_conversation_id"),
|
|
517
|
+
lastRunStatus: text("last_run_status"), // 'completed' | 'failed' | null
|
|
518
|
+
sourceType: text("source_type"), // reserved for future bridge (e.g. 'followup', 'triage')
|
|
519
|
+
sourceId: text("source_id"), // reserved for future bridge
|
|
520
|
+
requiredTools: text("required_tools"), // JSON array snapshot of tools needed for this run (null=unknown, []=none, ["bash",...]=specific)
|
|
521
|
+
approvedTools: text("approved_tools"), // JSON array of pre-approved tool names
|
|
522
|
+
approvalStatus: text("approval_status").default("none"), // 'none' | 'approved' | 'denied'
|
|
523
|
+
createdAt: integer("created_at").notNull(),
|
|
524
|
+
updatedAt: integer("updated_at").notNull(),
|
|
466
525
|
});
|
|
467
526
|
|
|
468
|
-
export const homeBaseAppLinks = sqliteTable(
|
|
469
|
-
id: text(
|
|
470
|
-
appId: text(
|
|
471
|
-
source: text(
|
|
472
|
-
createdAt: integer(
|
|
473
|
-
updatedAt: integer(
|
|
527
|
+
export const homeBaseAppLinks = sqliteTable("home_base_app_links", {
|
|
528
|
+
id: text("id").primaryKey(),
|
|
529
|
+
appId: text("app_id").notNull(),
|
|
530
|
+
source: text("source").notNull(),
|
|
531
|
+
createdAt: integer("created_at").notNull(),
|
|
532
|
+
updatedAt: integer("updated_at").notNull(),
|
|
474
533
|
});
|
|
475
534
|
|
|
476
|
-
export const publishedPages = sqliteTable(
|
|
477
|
-
id: text(
|
|
478
|
-
deploymentId: text(
|
|
479
|
-
publicUrl: text(
|
|
480
|
-
pageTitle: text(
|
|
481
|
-
htmlHash: text(
|
|
482
|
-
publishedAt: integer(
|
|
483
|
-
status: text(
|
|
484
|
-
appId: text(
|
|
485
|
-
projectSlug: text(
|
|
535
|
+
export const publishedPages = sqliteTable("published_pages", {
|
|
536
|
+
id: text("id").primaryKey(),
|
|
537
|
+
deploymentId: text("deployment_id").notNull().unique(),
|
|
538
|
+
publicUrl: text("public_url").notNull(),
|
|
539
|
+
pageTitle: text("page_title"),
|
|
540
|
+
htmlHash: text("html_hash").notNull(),
|
|
541
|
+
publishedAt: integer("published_at").notNull(),
|
|
542
|
+
status: text("status").notNull().default("active"),
|
|
543
|
+
appId: text("app_id"),
|
|
544
|
+
projectSlug: text("project_slug"),
|
|
486
545
|
});
|
|
487
546
|
|
|
488
547
|
// ── Watchers (event-driven polling) ──────────────────────────────────
|
|
489
548
|
|
|
490
|
-
export const watchers = sqliteTable(
|
|
491
|
-
id: text(
|
|
492
|
-
name: text(
|
|
493
|
-
providerId: text(
|
|
494
|
-
enabled: integer(
|
|
495
|
-
pollIntervalMs: integer(
|
|
496
|
-
actionPrompt: text(
|
|
497
|
-
watermark: text(
|
|
498
|
-
conversationId: text(
|
|
499
|
-
status: text(
|
|
500
|
-
consecutiveErrors: integer(
|
|
501
|
-
lastError: text(
|
|
502
|
-
lastPollAt: integer(
|
|
503
|
-
nextPollAt: integer(
|
|
504
|
-
configJson: text(
|
|
505
|
-
credentialService: text(
|
|
506
|
-
createdAt: integer(
|
|
507
|
-
updatedAt: integer(
|
|
549
|
+
export const watchers = sqliteTable("watchers", {
|
|
550
|
+
id: text("id").primaryKey(),
|
|
551
|
+
name: text("name").notNull(),
|
|
552
|
+
providerId: text("provider_id").notNull(),
|
|
553
|
+
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
|
|
554
|
+
pollIntervalMs: integer("poll_interval_ms").notNull().default(60000),
|
|
555
|
+
actionPrompt: text("action_prompt").notNull(),
|
|
556
|
+
watermark: text("watermark"),
|
|
557
|
+
conversationId: text("conversation_id"),
|
|
558
|
+
status: text("status").notNull().default("idle"), // idle | polling | error | disabled
|
|
559
|
+
consecutiveErrors: integer("consecutive_errors").notNull().default(0),
|
|
560
|
+
lastError: text("last_error"),
|
|
561
|
+
lastPollAt: integer("last_poll_at"),
|
|
562
|
+
nextPollAt: integer("next_poll_at").notNull(),
|
|
563
|
+
configJson: text("config_json"),
|
|
564
|
+
credentialService: text("credential_service").notNull(),
|
|
565
|
+
createdAt: integer("created_at").notNull(),
|
|
566
|
+
updatedAt: integer("updated_at").notNull(),
|
|
508
567
|
});
|
|
509
568
|
|
|
510
|
-
export const watcherEvents = sqliteTable(
|
|
511
|
-
id: text(
|
|
512
|
-
watcherId: text(
|
|
569
|
+
export const watcherEvents = sqliteTable("watcher_events", {
|
|
570
|
+
id: text("id").primaryKey(),
|
|
571
|
+
watcherId: text("watcher_id")
|
|
513
572
|
.notNull()
|
|
514
|
-
.references(() => watchers.id, { onDelete:
|
|
515
|
-
externalId: text(
|
|
516
|
-
eventType: text(
|
|
517
|
-
summary: text(
|
|
518
|
-
payloadJson: text(
|
|
519
|
-
disposition: text(
|
|
520
|
-
llmAction: text(
|
|
521
|
-
processedAt: integer(
|
|
522
|
-
createdAt: integer(
|
|
573
|
+
.references(() => watchers.id, { onDelete: "cascade" }),
|
|
574
|
+
externalId: text("external_id").notNull(),
|
|
575
|
+
eventType: text("event_type").notNull(),
|
|
576
|
+
summary: text("summary").notNull(),
|
|
577
|
+
payloadJson: text("payload_json").notNull(),
|
|
578
|
+
disposition: text("disposition").notNull().default("pending"), // pending | silent | notify | escalate | error
|
|
579
|
+
llmAction: text("llm_action"),
|
|
580
|
+
processedAt: integer("processed_at"),
|
|
581
|
+
createdAt: integer("created_at").notNull(),
|
|
523
582
|
});
|
|
524
583
|
|
|
525
|
-
export const llmRequestLogs = sqliteTable(
|
|
526
|
-
id: text(
|
|
527
|
-
conversationId: text(
|
|
528
|
-
requestPayload: text(
|
|
529
|
-
responsePayload: text(
|
|
530
|
-
createdAt: integer(
|
|
584
|
+
export const llmRequestLogs = sqliteTable("llm_request_logs", {
|
|
585
|
+
id: text("id").primaryKey(),
|
|
586
|
+
conversationId: text("conversation_id").notNull(),
|
|
587
|
+
requestPayload: text("request_payload").notNull(),
|
|
588
|
+
responsePayload: text("response_payload").notNull(),
|
|
589
|
+
createdAt: integer("created_at").notNull(),
|
|
531
590
|
});
|
|
532
591
|
|
|
533
|
-
export const llmUsageEvents = sqliteTable(
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
592
|
+
export const llmUsageEvents = sqliteTable(
|
|
593
|
+
"llm_usage_events",
|
|
594
|
+
{
|
|
595
|
+
id: text("id").primaryKey(),
|
|
596
|
+
createdAt: integer("created_at").notNull(),
|
|
597
|
+
conversationId: text("conversation_id"),
|
|
598
|
+
runId: text("run_id"),
|
|
599
|
+
requestId: text("request_id"),
|
|
600
|
+
actor: text("actor").notNull(),
|
|
601
|
+
provider: text("provider").notNull(),
|
|
602
|
+
model: text("model").notNull(),
|
|
603
|
+
inputTokens: integer("input_tokens").notNull(),
|
|
604
|
+
outputTokens: integer("output_tokens").notNull(),
|
|
605
|
+
cacheCreationInputTokens: integer("cache_creation_input_tokens"),
|
|
606
|
+
cacheReadInputTokens: integer("cache_read_input_tokens"),
|
|
607
|
+
estimatedCostUsd: real("estimated_cost_usd"),
|
|
608
|
+
pricingStatus: text("pricing_status").notNull(),
|
|
609
|
+
metadataJson: text("metadata_json"),
|
|
610
|
+
},
|
|
611
|
+
(table) => [
|
|
612
|
+
index("idx_llm_usage_events_conversation_id").on(table.conversationId),
|
|
613
|
+
],
|
|
614
|
+
);
|
|
552
615
|
|
|
553
616
|
// ── Call Sessions (outgoing AI phone calls) ──────────────────────────
|
|
554
617
|
|
|
555
|
-
export const callSessions = sqliteTable(
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
.
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
618
|
+
export const callSessions = sqliteTable(
|
|
619
|
+
"call_sessions",
|
|
620
|
+
{
|
|
621
|
+
id: text("id").primaryKey(),
|
|
622
|
+
conversationId: text("conversation_id")
|
|
623
|
+
.notNull()
|
|
624
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
625
|
+
provider: text("provider").notNull(),
|
|
626
|
+
providerCallSid: text("provider_call_sid"),
|
|
627
|
+
fromNumber: text("from_number").notNull(),
|
|
628
|
+
toNumber: text("to_number").notNull(),
|
|
629
|
+
task: text("task"),
|
|
630
|
+
status: text("status").notNull().default("initiated"),
|
|
631
|
+
callMode: text("call_mode"),
|
|
632
|
+
guardianVerificationSessionId: text("guardian_verification_session_id"),
|
|
633
|
+
callerIdentityMode: text("caller_identity_mode"),
|
|
634
|
+
callerIdentitySource: text("caller_identity_source"),
|
|
635
|
+
assistantId: text("assistant_id"),
|
|
636
|
+
initiatedFromConversationId: text("initiated_from_conversation_id"),
|
|
637
|
+
startedAt: integer("started_at"),
|
|
638
|
+
endedAt: integer("ended_at"),
|
|
639
|
+
lastError: text("last_error"),
|
|
640
|
+
createdAt: integer("created_at").notNull(),
|
|
641
|
+
updatedAt: integer("updated_at").notNull(),
|
|
642
|
+
},
|
|
643
|
+
(table) => [index("idx_call_sessions_status").on(table.status)],
|
|
644
|
+
);
|
|
645
|
+
|
|
646
|
+
export const callEvents = sqliteTable("call_events", {
|
|
647
|
+
id: text("id").primaryKey(),
|
|
648
|
+
callSessionId: text("call_session_id")
|
|
584
649
|
.notNull()
|
|
585
|
-
.references(() => callSessions.id, { onDelete:
|
|
586
|
-
eventType: text(
|
|
587
|
-
payloadJson: text(
|
|
588
|
-
createdAt: integer(
|
|
650
|
+
.references(() => callSessions.id, { onDelete: "cascade" }),
|
|
651
|
+
eventType: text("event_type").notNull(),
|
|
652
|
+
payloadJson: text("payload_json").notNull().default("{}"),
|
|
653
|
+
createdAt: integer("created_at").notNull(),
|
|
589
654
|
});
|
|
590
655
|
|
|
591
|
-
export const callPendingQuestions = sqliteTable(
|
|
592
|
-
id: text(
|
|
593
|
-
callSessionId: text(
|
|
656
|
+
export const callPendingQuestions = sqliteTable("call_pending_questions", {
|
|
657
|
+
id: text("id").primaryKey(),
|
|
658
|
+
callSessionId: text("call_session_id")
|
|
594
659
|
.notNull()
|
|
595
|
-
.references(() => callSessions.id, { onDelete:
|
|
596
|
-
questionText: text(
|
|
597
|
-
status: text(
|
|
598
|
-
askedAt: integer(
|
|
599
|
-
answeredAt: integer(
|
|
600
|
-
answerText: text(
|
|
660
|
+
.references(() => callSessions.id, { onDelete: "cascade" }),
|
|
661
|
+
questionText: text("question_text").notNull(),
|
|
662
|
+
status: text("status").notNull().default("pending"),
|
|
663
|
+
askedAt: integer("asked_at").notNull(),
|
|
664
|
+
answeredAt: integer("answered_at"),
|
|
665
|
+
answerText: text("answer_text"),
|
|
601
666
|
});
|
|
602
667
|
|
|
603
|
-
export const processedCallbacks = sqliteTable(
|
|
604
|
-
id: text(
|
|
605
|
-
dedupeKey: text(
|
|
606
|
-
callSessionId: text(
|
|
668
|
+
export const processedCallbacks = sqliteTable("processed_callbacks", {
|
|
669
|
+
id: text("id").primaryKey(),
|
|
670
|
+
dedupeKey: text("dedupe_key").notNull().unique(),
|
|
671
|
+
callSessionId: text("call_session_id")
|
|
607
672
|
.notNull()
|
|
608
|
-
.references(() => callSessions.id, { onDelete:
|
|
609
|
-
claimId: text(
|
|
610
|
-
createdAt: integer(
|
|
673
|
+
.references(() => callSessions.id, { onDelete: "cascade" }),
|
|
674
|
+
claimId: text("claim_id"),
|
|
675
|
+
createdAt: integer("created_at").notNull(),
|
|
611
676
|
});
|
|
612
677
|
|
|
613
678
|
// ── External Conversation Bindings ───────────────────────────────────
|
|
614
679
|
// UNIQUE (source_channel, external_chat_id) enforced via idx_ext_conv_bindings_channel_chat_unique in db.ts
|
|
615
680
|
|
|
616
|
-
export const externalConversationBindings = sqliteTable(
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
681
|
+
export const externalConversationBindings = sqliteTable(
|
|
682
|
+
"external_conversation_bindings",
|
|
683
|
+
{
|
|
684
|
+
conversationId: text("conversation_id")
|
|
685
|
+
.primaryKey()
|
|
686
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
687
|
+
sourceChannel: text("source_channel").notNull(),
|
|
688
|
+
externalChatId: text("external_chat_id").notNull(),
|
|
689
|
+
externalUserId: text("external_user_id"),
|
|
690
|
+
displayName: text("display_name"),
|
|
691
|
+
username: text("username"),
|
|
692
|
+
createdAt: integer("created_at").notNull(),
|
|
693
|
+
updatedAt: integer("updated_at").notNull(),
|
|
694
|
+
lastInboundAt: integer("last_inbound_at"),
|
|
695
|
+
lastOutboundAt: integer("last_outbound_at"),
|
|
696
|
+
},
|
|
697
|
+
);
|
|
630
698
|
|
|
631
699
|
// ── Channel Guardian Bindings ────────────────────────────────────────
|
|
632
700
|
// UNIQUE (assistant_id, channel) WHERE status = 'active' enforced via index in db.ts
|
|
633
701
|
|
|
634
|
-
export const channelGuardianBindings = sqliteTable(
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
702
|
+
export const channelGuardianBindings = sqliteTable(
|
|
703
|
+
"channel_guardian_bindings",
|
|
704
|
+
{
|
|
705
|
+
id: text("id").primaryKey(),
|
|
706
|
+
assistantId: text("assistant_id").notNull(),
|
|
707
|
+
channel: text("channel").notNull(),
|
|
708
|
+
guardianExternalUserId: text("guardian_external_user_id").notNull(),
|
|
709
|
+
guardianDeliveryChatId: text("guardian_delivery_chat_id").notNull(),
|
|
710
|
+
guardianPrincipalId: text("guardian_principal_id").notNull(),
|
|
711
|
+
status: text("status").notNull().default("active"),
|
|
712
|
+
verifiedAt: integer("verified_at").notNull(),
|
|
713
|
+
verifiedVia: text("verified_via").notNull().default("challenge"),
|
|
714
|
+
metadataJson: text("metadata_json"),
|
|
715
|
+
createdAt: integer("created_at").notNull(),
|
|
716
|
+
updatedAt: integer("updated_at").notNull(),
|
|
717
|
+
},
|
|
718
|
+
);
|
|
648
719
|
|
|
649
720
|
// ── Channel Guardian Verification Challenges ─────────────────────────
|
|
650
721
|
|
|
651
|
-
export const channelGuardianVerificationChallenges = sqliteTable(
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
722
|
+
export const channelGuardianVerificationChallenges = sqliteTable(
|
|
723
|
+
"channel_guardian_verification_challenges",
|
|
724
|
+
{
|
|
725
|
+
id: text("id").primaryKey(),
|
|
726
|
+
assistantId: text("assistant_id").notNull(),
|
|
727
|
+
channel: text("channel").notNull(),
|
|
728
|
+
challengeHash: text("challenge_hash").notNull(),
|
|
729
|
+
expiresAt: integer("expires_at").notNull(),
|
|
730
|
+
status: text("status").notNull().default("pending"),
|
|
731
|
+
createdBySessionId: text("created_by_session_id"),
|
|
732
|
+
consumedByExternalUserId: text("consumed_by_external_user_id"),
|
|
733
|
+
consumedByChatId: text("consumed_by_chat_id"),
|
|
734
|
+
// Outbound session: expected-identity binding
|
|
735
|
+
expectedExternalUserId: text("expected_external_user_id"),
|
|
736
|
+
expectedChatId: text("expected_chat_id"),
|
|
737
|
+
expectedPhoneE164: text("expected_phone_e164"),
|
|
738
|
+
identityBindingStatus: text("identity_binding_status").default("bound"),
|
|
739
|
+
// Outbound session: delivery tracking
|
|
740
|
+
destinationAddress: text("destination_address"),
|
|
741
|
+
lastSentAt: integer("last_sent_at"),
|
|
742
|
+
sendCount: integer("send_count").default(0),
|
|
743
|
+
nextResendAt: integer("next_resend_at"),
|
|
744
|
+
// Session configuration
|
|
745
|
+
codeDigits: integer("code_digits").default(6),
|
|
746
|
+
maxAttempts: integer("max_attempts").default(3),
|
|
747
|
+
// Distinguishes guardian verification from trusted contact verification
|
|
748
|
+
verificationPurpose: text("verification_purpose").default("guardian"),
|
|
749
|
+
// Telegram bootstrap deep-link token hash
|
|
750
|
+
bootstrapTokenHash: text("bootstrap_token_hash"),
|
|
751
|
+
createdAt: integer("created_at").notNull(),
|
|
752
|
+
updatedAt: integer("updated_at").notNull(),
|
|
753
|
+
},
|
|
754
|
+
);
|
|
681
755
|
|
|
682
756
|
// ── Channel Guardian Approval Requests ───────────────────────────────
|
|
683
757
|
|
|
684
|
-
export const channelGuardianApprovalRequests = sqliteTable(
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
758
|
+
export const channelGuardianApprovalRequests = sqliteTable(
|
|
759
|
+
"channel_guardian_approval_requests",
|
|
760
|
+
{
|
|
761
|
+
id: text("id").primaryKey(),
|
|
762
|
+
runId: text("run_id").notNull(),
|
|
763
|
+
requestId: text("request_id"),
|
|
764
|
+
conversationId: text("conversation_id").notNull(),
|
|
765
|
+
assistantId: text("assistant_id")
|
|
766
|
+
.notNull()
|
|
767
|
+
.default(DAEMON_INTERNAL_ASSISTANT_ID),
|
|
768
|
+
channel: text("channel").notNull(),
|
|
769
|
+
requesterExternalUserId: text("requester_external_user_id").notNull(),
|
|
770
|
+
requesterChatId: text("requester_chat_id").notNull(),
|
|
771
|
+
guardianExternalUserId: text("guardian_external_user_id").notNull(),
|
|
772
|
+
guardianChatId: text("guardian_chat_id").notNull(),
|
|
773
|
+
toolName: text("tool_name").notNull(),
|
|
774
|
+
riskLevel: text("risk_level"),
|
|
775
|
+
reason: text("reason"),
|
|
776
|
+
status: text("status").notNull().default("pending"),
|
|
777
|
+
decidedByExternalUserId: text("decided_by_external_user_id"),
|
|
778
|
+
expiresAt: integer("expires_at").notNull(),
|
|
779
|
+
createdAt: integer("created_at").notNull(),
|
|
780
|
+
updatedAt: integer("updated_at").notNull(),
|
|
781
|
+
},
|
|
782
|
+
);
|
|
704
783
|
|
|
705
784
|
// ── Channel Guardian Verification Rate Limits ────────────────────────
|
|
706
785
|
|
|
707
|
-
export const channelGuardianRateLimits = sqliteTable(
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
786
|
+
export const channelGuardianRateLimits = sqliteTable(
|
|
787
|
+
"channel_guardian_rate_limits",
|
|
788
|
+
{
|
|
789
|
+
id: text("id").primaryKey(),
|
|
790
|
+
assistantId: text("assistant_id").notNull(),
|
|
791
|
+
channel: text("channel").notNull(),
|
|
792
|
+
actorExternalUserId: text("actor_external_user_id").notNull(),
|
|
793
|
+
actorChatId: text("actor_chat_id").notNull(),
|
|
794
|
+
// Legacy columns kept with defaults for backward compatibility with upgraded databases
|
|
795
|
+
// that still have the old NOT NULL columns without DEFAULT. Not read by app logic.
|
|
796
|
+
invalidAttempts: integer("invalid_attempts").notNull().default(0),
|
|
797
|
+
windowStartedAt: integer("window_started_at").notNull().default(0),
|
|
798
|
+
attemptTimestampsJson: text("attempt_timestamps_json")
|
|
799
|
+
.notNull()
|
|
800
|
+
.default("[]"),
|
|
801
|
+
lockedUntil: integer("locked_until"),
|
|
802
|
+
createdAt: integer("created_at").notNull(),
|
|
803
|
+
updatedAt: integer("updated_at").notNull(),
|
|
804
|
+
},
|
|
805
|
+
);
|
|
722
806
|
|
|
723
807
|
// ── Media Assets ─────────────────────────────────────────────────────
|
|
724
808
|
|
|
725
|
-
export const mediaAssets = sqliteTable(
|
|
726
|
-
id: text(
|
|
727
|
-
title: text(
|
|
728
|
-
filePath: text(
|
|
729
|
-
mimeType: text(
|
|
730
|
-
durationSeconds: real(
|
|
731
|
-
fileHash: text(
|
|
732
|
-
status: text(
|
|
733
|
-
mediaType: text(
|
|
734
|
-
metadata: text(
|
|
735
|
-
createdAt: integer(
|
|
736
|
-
updatedAt: integer(
|
|
809
|
+
export const mediaAssets = sqliteTable("media_assets", {
|
|
810
|
+
id: text("id").primaryKey(),
|
|
811
|
+
title: text("title").notNull(),
|
|
812
|
+
filePath: text("file_path").notNull(),
|
|
813
|
+
mimeType: text("mime_type").notNull(),
|
|
814
|
+
durationSeconds: real("duration_seconds"),
|
|
815
|
+
fileHash: text("file_hash").notNull(),
|
|
816
|
+
status: text("status").notNull().default("registered"), // registered | processing | indexed | failed
|
|
817
|
+
mediaType: text("media_type").notNull(), // video | audio | image
|
|
818
|
+
metadata: text("metadata"), // JSON
|
|
819
|
+
createdAt: integer("created_at").notNull(),
|
|
820
|
+
updatedAt: integer("updated_at").notNull(),
|
|
737
821
|
});
|
|
738
822
|
|
|
739
|
-
export const processingStages = sqliteTable(
|
|
740
|
-
id: text(
|
|
741
|
-
assetId: text(
|
|
742
|
-
.
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
823
|
+
export const processingStages = sqliteTable("processing_stages", {
|
|
824
|
+
id: text("id").primaryKey(),
|
|
825
|
+
assetId: text("asset_id")
|
|
826
|
+
.notNull()
|
|
827
|
+
.references(() => mediaAssets.id, { onDelete: "cascade" }),
|
|
828
|
+
stage: text("stage").notNull(),
|
|
829
|
+
status: text("status").notNull().default("pending"), // pending | running | completed | failed
|
|
830
|
+
progress: integer("progress").notNull().default(0), // 0-100
|
|
831
|
+
lastError: text("last_error"),
|
|
832
|
+
startedAt: integer("started_at"),
|
|
833
|
+
completedAt: integer("completed_at"),
|
|
749
834
|
});
|
|
750
835
|
|
|
751
|
-
export const mediaKeyframes = sqliteTable(
|
|
752
|
-
id: text(
|
|
753
|
-
assetId: text(
|
|
754
|
-
.
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
836
|
+
export const mediaKeyframes = sqliteTable("media_keyframes", {
|
|
837
|
+
id: text("id").primaryKey(),
|
|
838
|
+
assetId: text("asset_id")
|
|
839
|
+
.notNull()
|
|
840
|
+
.references(() => mediaAssets.id, { onDelete: "cascade" }),
|
|
841
|
+
timestamp: real("timestamp").notNull(),
|
|
842
|
+
filePath: text("file_path").notNull(),
|
|
843
|
+
metadata: text("metadata"), // JSON
|
|
844
|
+
createdAt: integer("created_at").notNull(),
|
|
759
845
|
});
|
|
760
846
|
|
|
761
|
-
export const mediaVisionOutputs = sqliteTable(
|
|
762
|
-
id: text(
|
|
763
|
-
assetId: text(
|
|
764
|
-
.
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
847
|
+
export const mediaVisionOutputs = sqliteTable("media_vision_outputs", {
|
|
848
|
+
id: text("id").primaryKey(),
|
|
849
|
+
assetId: text("asset_id")
|
|
850
|
+
.notNull()
|
|
851
|
+
.references(() => mediaAssets.id, { onDelete: "cascade" }),
|
|
852
|
+
keyframeId: text("keyframe_id")
|
|
853
|
+
.notNull()
|
|
854
|
+
.references(() => mediaKeyframes.id, { onDelete: "cascade" }),
|
|
855
|
+
analysisType: text("analysis_type").notNull(),
|
|
856
|
+
output: text("output").notNull(), // JSON
|
|
857
|
+
confidence: real("confidence"),
|
|
858
|
+
createdAt: integer("created_at").notNull(),
|
|
771
859
|
});
|
|
772
860
|
|
|
773
|
-
export const mediaTimelines = sqliteTable(
|
|
774
|
-
id: text(
|
|
775
|
-
assetId: text(
|
|
776
|
-
.
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
861
|
+
export const mediaTimelines = sqliteTable("media_timelines", {
|
|
862
|
+
id: text("id").primaryKey(),
|
|
863
|
+
assetId: text("asset_id")
|
|
864
|
+
.notNull()
|
|
865
|
+
.references(() => mediaAssets.id, { onDelete: "cascade" }),
|
|
866
|
+
startTime: real("start_time").notNull(),
|
|
867
|
+
endTime: real("end_time").notNull(),
|
|
868
|
+
segmentType: text("segment_type").notNull(),
|
|
869
|
+
attributes: text("attributes"), // JSON
|
|
870
|
+
confidence: real("confidence"),
|
|
871
|
+
createdAt: integer("created_at").notNull(),
|
|
783
872
|
});
|
|
784
873
|
|
|
785
|
-
export const mediaEvents = sqliteTable(
|
|
786
|
-
id: text(
|
|
787
|
-
assetId: text(
|
|
788
|
-
.
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
874
|
+
export const mediaEvents = sqliteTable("media_events", {
|
|
875
|
+
id: text("id").primaryKey(),
|
|
876
|
+
assetId: text("asset_id")
|
|
877
|
+
.notNull()
|
|
878
|
+
.references(() => mediaAssets.id, { onDelete: "cascade" }),
|
|
879
|
+
eventType: text("event_type").notNull(),
|
|
880
|
+
startTime: real("start_time").notNull(),
|
|
881
|
+
endTime: real("end_time").notNull(),
|
|
882
|
+
confidence: real("confidence").notNull(),
|
|
883
|
+
reasons: text("reasons").notNull(), // JSON array
|
|
884
|
+
metadata: text("metadata"), // JSON
|
|
885
|
+
createdAt: integer("created_at").notNull(),
|
|
796
886
|
});
|
|
797
887
|
|
|
798
|
-
export const mediaTrackingProfiles = sqliteTable(
|
|
799
|
-
id: text(
|
|
800
|
-
assetId: text(
|
|
801
|
-
.
|
|
802
|
-
|
|
803
|
-
|
|
888
|
+
export const mediaTrackingProfiles = sqliteTable("media_tracking_profiles", {
|
|
889
|
+
id: text("id").primaryKey(),
|
|
890
|
+
assetId: text("asset_id")
|
|
891
|
+
.notNull()
|
|
892
|
+
.references(() => mediaAssets.id, { onDelete: "cascade" }),
|
|
893
|
+
capabilities: text("capabilities").notNull(), // JSON: { [capName]: { enabled, tier } }
|
|
894
|
+
createdAt: integer("created_at").notNull(),
|
|
804
895
|
});
|
|
805
896
|
|
|
806
|
-
export const mediaEventFeedback = sqliteTable(
|
|
807
|
-
id: text(
|
|
808
|
-
assetId: text(
|
|
809
|
-
.
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
897
|
+
export const mediaEventFeedback = sqliteTable("media_event_feedback", {
|
|
898
|
+
id: text("id").primaryKey(),
|
|
899
|
+
assetId: text("asset_id")
|
|
900
|
+
.notNull()
|
|
901
|
+
.references(() => mediaAssets.id, { onDelete: "cascade" }),
|
|
902
|
+
eventId: text("event_id")
|
|
903
|
+
.notNull()
|
|
904
|
+
.references(() => mediaEvents.id, { onDelete: "cascade" }),
|
|
905
|
+
feedbackType: text("feedback_type").notNull(), // correct | incorrect | boundary_edit | missed
|
|
906
|
+
originalStartTime: real("original_start_time"),
|
|
907
|
+
originalEndTime: real("original_end_time"),
|
|
908
|
+
correctedStartTime: real("corrected_start_time"),
|
|
909
|
+
correctedEndTime: real("corrected_end_time"),
|
|
910
|
+
notes: text("notes"),
|
|
911
|
+
createdAt: integer("created_at").notNull(),
|
|
819
912
|
});
|
|
820
913
|
|
|
821
914
|
// ── Guardian Action Requests (cross-channel voice guardian) ──────────
|
|
822
915
|
|
|
823
|
-
export const guardianActionRequests = sqliteTable(
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
.notNull()
|
|
831
|
-
.
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
916
|
+
export const guardianActionRequests = sqliteTable(
|
|
917
|
+
"guardian_action_requests",
|
|
918
|
+
{
|
|
919
|
+
id: text("id").primaryKey(),
|
|
920
|
+
assistantId: text("assistant_id")
|
|
921
|
+
.notNull()
|
|
922
|
+
.default(DAEMON_INTERNAL_ASSISTANT_ID),
|
|
923
|
+
kind: text("kind").notNull(), // 'ask_guardian'
|
|
924
|
+
sourceChannel: text("source_channel").notNull(), // 'voice'
|
|
925
|
+
sourceConversationId: text("source_conversation_id").notNull(),
|
|
926
|
+
callSessionId: text("call_session_id")
|
|
927
|
+
.notNull()
|
|
928
|
+
.references(() => callSessions.id, { onDelete: "cascade" }),
|
|
929
|
+
pendingQuestionId: text("pending_question_id")
|
|
930
|
+
.notNull()
|
|
931
|
+
.references(() => callPendingQuestions.id, { onDelete: "cascade" }),
|
|
932
|
+
questionText: text("question_text").notNull(),
|
|
933
|
+
requestCode: text("request_code").notNull(), // short human-readable code for routing replies
|
|
934
|
+
status: text("status").notNull().default("pending"), // pending | answered | expired | cancelled
|
|
935
|
+
answerText: text("answer_text"),
|
|
936
|
+
answeredByChannel: text("answered_by_channel"),
|
|
937
|
+
answeredByExternalUserId: text("answered_by_external_user_id"),
|
|
938
|
+
answeredAt: integer("answered_at"),
|
|
939
|
+
expiresAt: integer("expires_at").notNull(),
|
|
940
|
+
expiredReason: text("expired_reason"), // call_timeout | sweep_timeout | cancelled
|
|
941
|
+
followupState: text("followup_state").notNull().default("none"), // none | awaiting_guardian_choice | dispatching | completed | declined | failed
|
|
942
|
+
lateAnswerText: text("late_answer_text"),
|
|
943
|
+
lateAnsweredAt: integer("late_answered_at"),
|
|
944
|
+
followupAction: text("followup_action"), // call_back | message_back | decline
|
|
945
|
+
followupCompletedAt: integer("followup_completed_at"),
|
|
946
|
+
toolName: text("tool_name"), // tool identity for tool-approval requests
|
|
947
|
+
inputDigest: text("input_digest"), // canonical SHA-256 digest of tool input
|
|
948
|
+
supersededByRequestId: text("superseded_by_request_id"), // links to the request that replaced this one
|
|
949
|
+
supersededAt: integer("superseded_at"), // epoch ms when supersession occurred
|
|
950
|
+
createdAt: integer("created_at").notNull(),
|
|
951
|
+
updatedAt: integer("updated_at").notNull(),
|
|
952
|
+
},
|
|
953
|
+
(table) => [
|
|
954
|
+
index("idx_guardian_action_requests_session_status_created").on(
|
|
955
|
+
table.callSessionId,
|
|
956
|
+
table.status,
|
|
957
|
+
table.createdAt,
|
|
958
|
+
),
|
|
959
|
+
],
|
|
960
|
+
);
|
|
858
961
|
|
|
859
962
|
// ── Guardian Action Deliveries (per-channel delivery tracking) ───────
|
|
860
963
|
|
|
861
|
-
export const guardianActionDeliveries = sqliteTable(
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
.
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
964
|
+
export const guardianActionDeliveries = sqliteTable(
|
|
965
|
+
"guardian_action_deliveries",
|
|
966
|
+
{
|
|
967
|
+
id: text("id").primaryKey(),
|
|
968
|
+
requestId: text("request_id")
|
|
969
|
+
.notNull()
|
|
970
|
+
.references(() => guardianActionRequests.id, { onDelete: "cascade" }),
|
|
971
|
+
destinationChannel: text("destination_channel").notNull(), // 'telegram' | 'sms' | 'vellum'
|
|
972
|
+
destinationConversationId: text("destination_conversation_id"),
|
|
973
|
+
destinationChatId: text("destination_chat_id"),
|
|
974
|
+
destinationExternalUserId: text("destination_external_user_id"),
|
|
975
|
+
status: text("status").notNull().default("pending"), // pending | sent | failed | answered | expired | cancelled
|
|
976
|
+
sentAt: integer("sent_at"),
|
|
977
|
+
respondedAt: integer("responded_at"),
|
|
978
|
+
lastError: text("last_error"),
|
|
979
|
+
createdAt: integer("created_at").notNull(),
|
|
980
|
+
updatedAt: integer("updated_at").notNull(),
|
|
981
|
+
},
|
|
982
|
+
(table) => [
|
|
983
|
+
index("idx_guardian_action_deliveries_dest_conversation").on(
|
|
984
|
+
table.destinationConversationId,
|
|
985
|
+
),
|
|
986
|
+
],
|
|
987
|
+
);
|
|
879
988
|
|
|
880
989
|
// ── Canonical Guardian Requests (unified cross-source guardian domain) ─
|
|
881
990
|
|
|
882
|
-
export const canonicalGuardianRequests = sqliteTable(
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
991
|
+
export const canonicalGuardianRequests = sqliteTable(
|
|
992
|
+
"canonical_guardian_requests",
|
|
993
|
+
{
|
|
994
|
+
id: text("id").primaryKey(),
|
|
995
|
+
kind: text("kind").notNull(),
|
|
996
|
+
sourceType: text("source_type").notNull(),
|
|
997
|
+
sourceChannel: text("source_channel"),
|
|
998
|
+
conversationId: text("conversation_id"),
|
|
999
|
+
requesterExternalUserId: text("requester_external_user_id"),
|
|
1000
|
+
requesterChatId: text("requester_chat_id"),
|
|
1001
|
+
guardianExternalUserId: text("guardian_external_user_id"),
|
|
1002
|
+
guardianPrincipalId: text("guardian_principal_id"),
|
|
1003
|
+
callSessionId: text("call_session_id"),
|
|
1004
|
+
pendingQuestionId: text("pending_question_id"),
|
|
1005
|
+
questionText: text("question_text"),
|
|
1006
|
+
requestCode: text("request_code"),
|
|
1007
|
+
toolName: text("tool_name"),
|
|
1008
|
+
inputDigest: text("input_digest"),
|
|
1009
|
+
status: text("status").notNull().default("pending"),
|
|
1010
|
+
answerText: text("answer_text"),
|
|
1011
|
+
decidedByExternalUserId: text("decided_by_external_user_id"),
|
|
1012
|
+
decidedByPrincipalId: text("decided_by_principal_id"),
|
|
1013
|
+
followupState: text("followup_state"),
|
|
1014
|
+
expiresAt: text("expires_at"),
|
|
1015
|
+
createdAt: text("created_at").notNull(),
|
|
1016
|
+
updatedAt: text("updated_at").notNull(),
|
|
1017
|
+
},
|
|
1018
|
+
(table) => [
|
|
1019
|
+
index("idx_canonical_guardian_requests_status").on(table.status),
|
|
1020
|
+
index("idx_canonical_guardian_requests_guardian").on(
|
|
1021
|
+
table.guardianExternalUserId,
|
|
1022
|
+
table.status,
|
|
1023
|
+
),
|
|
1024
|
+
index("idx_canonical_guardian_requests_conversation").on(
|
|
1025
|
+
table.conversationId,
|
|
1026
|
+
table.status,
|
|
1027
|
+
),
|
|
1028
|
+
index("idx_canonical_guardian_requests_source").on(
|
|
1029
|
+
table.sourceType,
|
|
1030
|
+
table.status,
|
|
1031
|
+
),
|
|
1032
|
+
index("idx_canonical_guardian_requests_kind").on(table.kind, table.status),
|
|
1033
|
+
index("idx_canonical_guardian_requests_request_code").on(table.requestCode),
|
|
1034
|
+
],
|
|
1035
|
+
);
|
|
914
1036
|
|
|
915
1037
|
// ── Canonical Guardian Deliveries (per-channel delivery tracking) ─────
|
|
916
1038
|
|
|
917
|
-
export const canonicalGuardianDeliveries = sqliteTable(
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
.
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
1039
|
+
export const canonicalGuardianDeliveries = sqliteTable(
|
|
1040
|
+
"canonical_guardian_deliveries",
|
|
1041
|
+
{
|
|
1042
|
+
id: text("id").primaryKey(),
|
|
1043
|
+
requestId: text("request_id")
|
|
1044
|
+
.notNull()
|
|
1045
|
+
.references(() => canonicalGuardianRequests.id, { onDelete: "cascade" }),
|
|
1046
|
+
destinationChannel: text("destination_channel").notNull(),
|
|
1047
|
+
destinationConversationId: text("destination_conversation_id"),
|
|
1048
|
+
destinationChatId: text("destination_chat_id"),
|
|
1049
|
+
destinationMessageId: text("destination_message_id"),
|
|
1050
|
+
status: text("status").notNull().default("pending"),
|
|
1051
|
+
createdAt: text("created_at").notNull(),
|
|
1052
|
+
updatedAt: text("updated_at").notNull(),
|
|
1053
|
+
},
|
|
1054
|
+
(table) => [
|
|
1055
|
+
index("idx_canonical_guardian_deliveries_request_id").on(table.requestId),
|
|
1056
|
+
index("idx_canonical_guardian_deliveries_status").on(table.status),
|
|
1057
|
+
],
|
|
1058
|
+
);
|
|
933
1059
|
|
|
934
1060
|
// ── Assistant Inbox ──────────────────────────────────────────────────
|
|
935
1061
|
|
|
936
|
-
export const assistantIngressInvites = sqliteTable(
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1062
|
+
export const assistantIngressInvites = sqliteTable(
|
|
1063
|
+
"assistant_ingress_invites",
|
|
1064
|
+
{
|
|
1065
|
+
id: text("id").primaryKey(),
|
|
1066
|
+
assistantId: text("assistant_id")
|
|
1067
|
+
.notNull()
|
|
1068
|
+
.default(DAEMON_INTERNAL_ASSISTANT_ID),
|
|
1069
|
+
sourceChannel: text("source_channel").notNull(),
|
|
1070
|
+
tokenHash: text("token_hash").notNull(),
|
|
1071
|
+
createdBySessionId: text("created_by_session_id"),
|
|
1072
|
+
note: text("note"),
|
|
1073
|
+
maxUses: integer("max_uses").notNull().default(1),
|
|
1074
|
+
useCount: integer("use_count").notNull().default(0),
|
|
1075
|
+
expiresAt: integer("expires_at").notNull(),
|
|
1076
|
+
status: text("status").notNull().default("active"),
|
|
1077
|
+
redeemedByExternalUserId: text("redeemed_by_external_user_id"),
|
|
1078
|
+
redeemedByExternalChatId: text("redeemed_by_external_chat_id"),
|
|
1079
|
+
redeemedAt: integer("redeemed_at"),
|
|
1080
|
+
// Voice invite fields (nullable — non-voice invites leave these NULL)
|
|
1081
|
+
expectedExternalUserId: text("expected_external_user_id"),
|
|
1082
|
+
voiceCodeHash: text("voice_code_hash"),
|
|
1083
|
+
voiceCodeDigits: integer("voice_code_digits"),
|
|
1084
|
+
// Display metadata for personalized voice prompts (nullable — non-voice invites leave these NULL)
|
|
1085
|
+
friendName: text("friend_name"),
|
|
1086
|
+
guardianName: text("guardian_name"),
|
|
1087
|
+
createdAt: integer("created_at").notNull(),
|
|
1088
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1089
|
+
},
|
|
1090
|
+
);
|
|
1091
|
+
|
|
1092
|
+
export const assistantIngressMembers = sqliteTable(
|
|
1093
|
+
"assistant_ingress_members",
|
|
1094
|
+
{
|
|
1095
|
+
id: text("id").primaryKey(),
|
|
1096
|
+
assistantId: text("assistant_id")
|
|
1097
|
+
.notNull()
|
|
1098
|
+
.default(DAEMON_INTERNAL_ASSISTANT_ID),
|
|
1099
|
+
sourceChannel: text("source_channel").notNull(),
|
|
1100
|
+
externalUserId: text("external_user_id"),
|
|
1101
|
+
externalChatId: text("external_chat_id"),
|
|
1102
|
+
displayName: text("display_name"),
|
|
1103
|
+
username: text("username"),
|
|
1104
|
+
status: text("status").notNull().default("pending"),
|
|
1105
|
+
policy: text("policy").notNull().default("allow"),
|
|
1106
|
+
inviteId: text("invite_id").references(() => assistantIngressInvites.id, {
|
|
1107
|
+
onDelete: "cascade",
|
|
1108
|
+
}),
|
|
1109
|
+
createdBySessionId: text("created_by_session_id"),
|
|
1110
|
+
revokedReason: text("revoked_reason"),
|
|
1111
|
+
blockedReason: text("blocked_reason"),
|
|
1112
|
+
lastSeenAt: integer("last_seen_at"),
|
|
1113
|
+
createdAt: integer("created_at").notNull(),
|
|
1114
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1115
|
+
},
|
|
1116
|
+
);
|
|
1117
|
+
|
|
1118
|
+
export const assistantInboxThreadState = sqliteTable(
|
|
1119
|
+
"assistant_inbox_thread_state",
|
|
1120
|
+
{
|
|
1121
|
+
conversationId: text("conversation_id")
|
|
1122
|
+
.primaryKey()
|
|
1123
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
1124
|
+
assistantId: text("assistant_id")
|
|
1125
|
+
.notNull()
|
|
1126
|
+
.default(DAEMON_INTERNAL_ASSISTANT_ID),
|
|
1127
|
+
sourceChannel: text("source_channel").notNull(),
|
|
1128
|
+
externalChatId: text("external_chat_id").notNull(),
|
|
1129
|
+
externalUserId: text("external_user_id"),
|
|
1130
|
+
displayName: text("display_name"),
|
|
1131
|
+
username: text("username"),
|
|
1132
|
+
lastInboundAt: integer("last_inbound_at"),
|
|
1133
|
+
lastOutboundAt: integer("last_outbound_at"),
|
|
1134
|
+
lastMessageAt: integer("last_message_at"),
|
|
1135
|
+
unreadCount: integer("unread_count").notNull().default(0),
|
|
1136
|
+
pendingEscalationCount: integer("pending_escalation_count")
|
|
1137
|
+
.notNull()
|
|
1138
|
+
.default(0),
|
|
1139
|
+
hasPendingEscalation: integer("has_pending_escalation")
|
|
1140
|
+
.notNull()
|
|
1141
|
+
.default(0),
|
|
1142
|
+
createdAt: integer("created_at").notNull(),
|
|
1143
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1144
|
+
},
|
|
1145
|
+
);
|
|
1000
1146
|
|
|
1001
1147
|
// ── Notification System ──────────────────────────────────────────────
|
|
1002
1148
|
|
|
1003
|
-
export const notificationEvents = sqliteTable(
|
|
1004
|
-
id: text(
|
|
1005
|
-
assistantId: text(
|
|
1006
|
-
sourceEventName: text(
|
|
1007
|
-
sourceChannel: text(
|
|
1008
|
-
sourceSessionId: text(
|
|
1009
|
-
attentionHintsJson: text(
|
|
1010
|
-
payloadJson: text(
|
|
1011
|
-
dedupeKey: text(
|
|
1012
|
-
createdAt: integer(
|
|
1013
|
-
updatedAt: integer(
|
|
1149
|
+
export const notificationEvents = sqliteTable("notification_events", {
|
|
1150
|
+
id: text("id").primaryKey(),
|
|
1151
|
+
assistantId: text("assistant_id").notNull(),
|
|
1152
|
+
sourceEventName: text("source_event_name").notNull(),
|
|
1153
|
+
sourceChannel: text("source_channel").notNull(),
|
|
1154
|
+
sourceSessionId: text("source_session_id").notNull(),
|
|
1155
|
+
attentionHintsJson: text("attention_hints_json").notNull().default("{}"),
|
|
1156
|
+
payloadJson: text("payload_json").notNull().default("{}"),
|
|
1157
|
+
dedupeKey: text("dedupe_key"),
|
|
1158
|
+
createdAt: integer("created_at").notNull(),
|
|
1159
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1014
1160
|
});
|
|
1015
1161
|
|
|
1016
|
-
export const notificationDecisions = sqliteTable(
|
|
1017
|
-
id: text(
|
|
1018
|
-
notificationEventId: text(
|
|
1162
|
+
export const notificationDecisions = sqliteTable("notification_decisions", {
|
|
1163
|
+
id: text("id").primaryKey(),
|
|
1164
|
+
notificationEventId: text("notification_event_id")
|
|
1019
1165
|
.notNull()
|
|
1020
|
-
.references(() => notificationEvents.id, { onDelete:
|
|
1021
|
-
shouldNotify: integer(
|
|
1022
|
-
selectedChannels: text(
|
|
1023
|
-
reasoningSummary: text(
|
|
1024
|
-
confidence: real(
|
|
1025
|
-
fallbackUsed: integer(
|
|
1026
|
-
promptVersion: text(
|
|
1027
|
-
validationResults: text(
|
|
1028
|
-
createdAt: integer(
|
|
1166
|
+
.references(() => notificationEvents.id, { onDelete: "cascade" }),
|
|
1167
|
+
shouldNotify: integer("should_notify").notNull(),
|
|
1168
|
+
selectedChannels: text("selected_channels").notNull().default("[]"),
|
|
1169
|
+
reasoningSummary: text("reasoning_summary").notNull(),
|
|
1170
|
+
confidence: real("confidence").notNull(),
|
|
1171
|
+
fallbackUsed: integer("fallback_used").notNull().default(0),
|
|
1172
|
+
promptVersion: text("prompt_version"),
|
|
1173
|
+
validationResults: text("validation_results"),
|
|
1174
|
+
createdAt: integer("created_at").notNull(),
|
|
1029
1175
|
});
|
|
1030
1176
|
|
|
1031
|
-
export const notificationPreferences = sqliteTable(
|
|
1032
|
-
id: text(
|
|
1033
|
-
assistantId: text(
|
|
1034
|
-
preferenceText: text(
|
|
1035
|
-
appliesWhenJson: text(
|
|
1036
|
-
priority: integer(
|
|
1037
|
-
createdAt: integer(
|
|
1038
|
-
updatedAt: integer(
|
|
1177
|
+
export const notificationPreferences = sqliteTable("notification_preferences", {
|
|
1178
|
+
id: text("id").primaryKey(),
|
|
1179
|
+
assistantId: text("assistant_id").notNull(),
|
|
1180
|
+
preferenceText: text("preference_text").notNull(),
|
|
1181
|
+
appliesWhenJson: text("applies_when_json").notNull().default("{}"),
|
|
1182
|
+
priority: integer("priority").notNull().default(0),
|
|
1183
|
+
createdAt: integer("created_at").notNull(),
|
|
1184
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1039
1185
|
});
|
|
1040
1186
|
|
|
1041
1187
|
// ── Sequences (multi-step outreach) ──────────────────────────────────
|
|
1042
1188
|
|
|
1043
|
-
export const sequences = sqliteTable(
|
|
1044
|
-
id: text(
|
|
1045
|
-
name: text(
|
|
1046
|
-
description: text(
|
|
1047
|
-
channel: text(
|
|
1048
|
-
steps: text(
|
|
1049
|
-
exitOnReply: integer(
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1189
|
+
export const sequences = sqliteTable("sequences", {
|
|
1190
|
+
id: text("id").primaryKey(),
|
|
1191
|
+
name: text("name").notNull(),
|
|
1192
|
+
description: text("description"),
|
|
1193
|
+
channel: text("channel").notNull(),
|
|
1194
|
+
steps: text("steps").notNull(), // JSON array of SequenceStep
|
|
1195
|
+
exitOnReply: integer("exit_on_reply", { mode: "boolean" })
|
|
1196
|
+
.notNull()
|
|
1197
|
+
.default(true),
|
|
1198
|
+
status: text("status").notNull().default("active"), // active | paused | archived
|
|
1199
|
+
createdAt: integer("created_at").notNull(),
|
|
1200
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1053
1201
|
});
|
|
1054
1202
|
|
|
1055
|
-
export const sequenceEnrollments = sqliteTable(
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
.
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
.
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1203
|
+
export const sequenceEnrollments = sqliteTable(
|
|
1204
|
+
"sequence_enrollments",
|
|
1205
|
+
{
|
|
1206
|
+
id: text("id").primaryKey(),
|
|
1207
|
+
sequenceId: text("sequence_id")
|
|
1208
|
+
.notNull()
|
|
1209
|
+
.references(() => sequences.id, { onDelete: "cascade" }),
|
|
1210
|
+
contactEmail: text("contact_email").notNull(),
|
|
1211
|
+
contactName: text("contact_name"),
|
|
1212
|
+
currentStep: integer("current_step").notNull().default(0),
|
|
1213
|
+
status: text("status").notNull().default("active"), // active | paused | completed | replied | cancelled | failed
|
|
1214
|
+
threadId: text("thread_id"),
|
|
1215
|
+
nextStepAt: integer("next_step_at"), // epoch ms
|
|
1216
|
+
context: text("context"), // JSON
|
|
1217
|
+
createdAt: integer("created_at").notNull(),
|
|
1218
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1219
|
+
},
|
|
1220
|
+
(table) => [
|
|
1221
|
+
index("idx_seq_enrollments_status_next_step").on(
|
|
1222
|
+
table.status,
|
|
1223
|
+
table.nextStepAt,
|
|
1224
|
+
),
|
|
1225
|
+
index("idx_seq_enrollments_sequence_id").on(table.sequenceId),
|
|
1226
|
+
index("idx_seq_enrollments_contact_email").on(table.contactEmail),
|
|
1227
|
+
],
|
|
1228
|
+
);
|
|
1229
|
+
|
|
1230
|
+
export const notificationDeliveries = sqliteTable(
|
|
1231
|
+
"notification_deliveries",
|
|
1232
|
+
{
|
|
1233
|
+
id: text("id").primaryKey(),
|
|
1234
|
+
notificationDecisionId: text("notification_decision_id")
|
|
1235
|
+
.notNull()
|
|
1236
|
+
.references(() => notificationDecisions.id, { onDelete: "cascade" }),
|
|
1237
|
+
assistantId: text("assistant_id").notNull(),
|
|
1238
|
+
channel: text("channel").notNull(),
|
|
1239
|
+
destination: text("destination").notNull(),
|
|
1240
|
+
status: text("status").notNull().default("pending"),
|
|
1241
|
+
attempt: integer("attempt").notNull().default(1),
|
|
1242
|
+
renderedTitle: text("rendered_title"),
|
|
1243
|
+
renderedBody: text("rendered_body"),
|
|
1244
|
+
errorCode: text("error_code"),
|
|
1245
|
+
errorMessage: text("error_message"),
|
|
1246
|
+
sentAt: integer("sent_at"),
|
|
1247
|
+
conversationId: text("conversation_id"),
|
|
1248
|
+
messageId: text("message_id"),
|
|
1249
|
+
conversationStrategy: text("conversation_strategy"),
|
|
1250
|
+
threadAction: text("thread_action"),
|
|
1251
|
+
threadTargetConversationId: text("thread_target_conversation_id"),
|
|
1252
|
+
threadDecisionFallbackUsed: integer("thread_decision_fallback_used"),
|
|
1253
|
+
clientDeliveryStatus: text("client_delivery_status"),
|
|
1254
|
+
clientDeliveryError: text("client_delivery_error"),
|
|
1255
|
+
clientDeliveryAt: integer("client_delivery_at"),
|
|
1256
|
+
createdAt: integer("created_at").notNull(),
|
|
1257
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1258
|
+
},
|
|
1259
|
+
(table) => [
|
|
1260
|
+
uniqueIndex("idx_notification_deliveries_decision_channel").on(
|
|
1261
|
+
table.notificationDecisionId,
|
|
1262
|
+
table.channel,
|
|
1263
|
+
),
|
|
1264
|
+
],
|
|
1265
|
+
);
|
|
1104
1266
|
|
|
1105
1267
|
// ── Conversation Attention ───────────────────────────────────────────
|
|
1106
1268
|
|
|
1107
|
-
export const conversationAttentionEvents = sqliteTable(
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
.
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
.
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1269
|
+
export const conversationAttentionEvents = sqliteTable(
|
|
1270
|
+
"conversation_attention_events",
|
|
1271
|
+
{
|
|
1272
|
+
id: text("id").primaryKey(),
|
|
1273
|
+
conversationId: text("conversation_id")
|
|
1274
|
+
.notNull()
|
|
1275
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
1276
|
+
assistantId: text("assistant_id").notNull(),
|
|
1277
|
+
sourceChannel: text("source_channel").notNull(),
|
|
1278
|
+
signalType: text("signal_type").notNull(),
|
|
1279
|
+
confidence: text("confidence").notNull(),
|
|
1280
|
+
source: text("source").notNull(),
|
|
1281
|
+
evidenceText: text("evidence_text"),
|
|
1282
|
+
metadataJson: text("metadata_json").notNull().default("{}"),
|
|
1283
|
+
observedAt: integer("observed_at").notNull(),
|
|
1284
|
+
createdAt: integer("created_at").notNull(),
|
|
1285
|
+
},
|
|
1286
|
+
(table) => [
|
|
1287
|
+
index("idx_conv_attn_events_conv_observed").on(
|
|
1288
|
+
table.conversationId,
|
|
1289
|
+
table.observedAt,
|
|
1290
|
+
),
|
|
1291
|
+
index("idx_conv_attn_events_assistant_observed").on(
|
|
1292
|
+
table.assistantId,
|
|
1293
|
+
table.observedAt,
|
|
1294
|
+
),
|
|
1295
|
+
index("idx_conv_attn_events_channel_observed").on(
|
|
1296
|
+
table.sourceChannel,
|
|
1297
|
+
table.observedAt,
|
|
1298
|
+
),
|
|
1299
|
+
],
|
|
1300
|
+
);
|
|
1301
|
+
|
|
1302
|
+
export const conversationAssistantAttentionState = sqliteTable(
|
|
1303
|
+
"conversation_assistant_attention_state",
|
|
1304
|
+
{
|
|
1305
|
+
conversationId: text("conversation_id")
|
|
1306
|
+
.primaryKey()
|
|
1307
|
+
.references(() => conversations.id, { onDelete: "cascade" }),
|
|
1308
|
+
assistantId: text("assistant_id").notNull(),
|
|
1309
|
+
latestAssistantMessageId: text("latest_assistant_message_id"),
|
|
1310
|
+
latestAssistantMessageAt: integer("latest_assistant_message_at"),
|
|
1311
|
+
lastSeenAssistantMessageId: text("last_seen_assistant_message_id"),
|
|
1312
|
+
lastSeenAssistantMessageAt: integer("last_seen_assistant_message_at"),
|
|
1313
|
+
lastSeenEventAt: integer("last_seen_event_at"),
|
|
1314
|
+
lastSeenConfidence: text("last_seen_confidence"),
|
|
1315
|
+
lastSeenSignalType: text("last_seen_signal_type"),
|
|
1316
|
+
lastSeenSourceChannel: text("last_seen_source_channel"),
|
|
1317
|
+
lastSeenSource: text("last_seen_source"),
|
|
1318
|
+
lastSeenEvidenceText: text("last_seen_evidence_text"),
|
|
1319
|
+
createdAt: integer("created_at").notNull(),
|
|
1320
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1321
|
+
},
|
|
1322
|
+
(table) => [
|
|
1323
|
+
index("idx_conv_attn_state_assistant_latest_msg").on(
|
|
1324
|
+
table.assistantId,
|
|
1325
|
+
table.latestAssistantMessageAt,
|
|
1326
|
+
),
|
|
1327
|
+
index("idx_conv_attn_state_assistant_last_seen").on(
|
|
1328
|
+
table.assistantId,
|
|
1329
|
+
table.lastSeenAssistantMessageAt,
|
|
1330
|
+
),
|
|
1331
|
+
],
|
|
1332
|
+
);
|
|
1148
1333
|
|
|
1149
1334
|
// ── Actor Token Records ──────────────────────────────────────────────
|
|
1150
1335
|
|
|
1151
|
-
export const actorTokenRecords = sqliteTable(
|
|
1152
|
-
id: text(
|
|
1153
|
-
tokenHash: text(
|
|
1154
|
-
assistantId: text(
|
|
1155
|
-
guardianPrincipalId: text(
|
|
1156
|
-
hashedDeviceId: text(
|
|
1157
|
-
platform: text(
|
|
1158
|
-
status: text(
|
|
1159
|
-
issuedAt: integer(
|
|
1160
|
-
expiresAt: integer(
|
|
1161
|
-
createdAt: integer(
|
|
1162
|
-
updatedAt: integer(
|
|
1336
|
+
export const actorTokenRecords = sqliteTable("actor_token_records", {
|
|
1337
|
+
id: text("id").primaryKey(),
|
|
1338
|
+
tokenHash: text("token_hash").notNull(),
|
|
1339
|
+
assistantId: text("assistant_id").notNull(),
|
|
1340
|
+
guardianPrincipalId: text("guardian_principal_id").notNull(),
|
|
1341
|
+
hashedDeviceId: text("hashed_device_id").notNull(),
|
|
1342
|
+
platform: text("platform").notNull(),
|
|
1343
|
+
status: text("status").notNull().default("active"),
|
|
1344
|
+
issuedAt: integer("issued_at").notNull(),
|
|
1345
|
+
expiresAt: integer("expires_at"),
|
|
1346
|
+
createdAt: integer("created_at").notNull(),
|
|
1347
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1163
1348
|
});
|
|
1164
1349
|
|
|
1165
1350
|
// ── Actor Refresh Token Records ──────────────────────────────────────
|
|
1166
1351
|
|
|
1167
|
-
export const actorRefreshTokenRecords = sqliteTable(
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1352
|
+
export const actorRefreshTokenRecords = sqliteTable(
|
|
1353
|
+
"actor_refresh_token_records",
|
|
1354
|
+
{
|
|
1355
|
+
id: text("id").primaryKey(),
|
|
1356
|
+
tokenHash: text("token_hash").notNull(),
|
|
1357
|
+
familyId: text("family_id").notNull(),
|
|
1358
|
+
assistantId: text("assistant_id").notNull(),
|
|
1359
|
+
guardianPrincipalId: text("guardian_principal_id").notNull(),
|
|
1360
|
+
hashedDeviceId: text("hashed_device_id").notNull(),
|
|
1361
|
+
platform: text("platform").notNull(),
|
|
1362
|
+
status: text("status").notNull().default("active"),
|
|
1363
|
+
issuedAt: integer("issued_at").notNull(),
|
|
1364
|
+
absoluteExpiresAt: integer("absolute_expires_at").notNull(),
|
|
1365
|
+
inactivityExpiresAt: integer("inactivity_expires_at").notNull(),
|
|
1366
|
+
lastUsedAt: integer("last_used_at"),
|
|
1367
|
+
createdAt: integer("created_at").notNull(),
|
|
1368
|
+
updatedAt: integer("updated_at").notNull(),
|
|
1369
|
+
},
|
|
1370
|
+
);
|
|
1183
1371
|
|
|
1184
1372
|
// ── Scoped Approval Grants ──────────────────────────────────────────
|
|
1185
1373
|
|
|
1186
|
-
export const scopedApprovalGrants = sqliteTable(
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1374
|
+
export const scopedApprovalGrants = sqliteTable(
|
|
1375
|
+
"scoped_approval_grants",
|
|
1376
|
+
{
|
|
1377
|
+
id: text("id").primaryKey(),
|
|
1378
|
+
assistantId: text("assistant_id").notNull(),
|
|
1379
|
+
scopeMode: text("scope_mode").notNull(), // 'request_id' | 'tool_signature'
|
|
1380
|
+
requestId: text("request_id"),
|
|
1381
|
+
toolName: text("tool_name"),
|
|
1382
|
+
inputDigest: text("input_digest"),
|
|
1383
|
+
requestChannel: text("request_channel").notNull(),
|
|
1384
|
+
decisionChannel: text("decision_channel").notNull(),
|
|
1385
|
+
executionChannel: text("execution_channel"), // null = any channel
|
|
1386
|
+
conversationId: text("conversation_id"),
|
|
1387
|
+
callSessionId: text("call_session_id"),
|
|
1388
|
+
requesterExternalUserId: text("requester_external_user_id"),
|
|
1389
|
+
guardianExternalUserId: text("guardian_external_user_id"),
|
|
1390
|
+
status: text("status").notNull(), // 'active' | 'consumed' | 'expired' | 'revoked'
|
|
1391
|
+
expiresAt: text("expires_at").notNull(),
|
|
1392
|
+
consumedAt: text("consumed_at"),
|
|
1393
|
+
consumedByRequestId: text("consumed_by_request_id"),
|
|
1394
|
+
createdAt: text("created_at").notNull(),
|
|
1395
|
+
updatedAt: text("updated_at").notNull(),
|
|
1396
|
+
},
|
|
1397
|
+
(table) => [
|
|
1398
|
+
index("idx_scoped_grants_request_id").on(table.requestId),
|
|
1399
|
+
index("idx_scoped_grants_tool_sig").on(table.toolName, table.inputDigest),
|
|
1400
|
+
index("idx_scoped_grants_status_expires").on(table.status, table.expiresAt),
|
|
1401
|
+
],
|
|
1402
|
+
);
|