@opengeni/db 0.27.11 → 0.28.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-JYQPJ6Y5.js → chunk-P6CUHXQZ.js} +2967 -2272
- package/dist/chunk-P6CUHXQZ.js.map +1 -0
- package/dist/{chunk-RPHPNVWW.js → chunk-VHBFHMPC.js} +15 -1
- package/dist/chunk-VHBFHMPC.js.map +1 -0
- package/dist/environment-crypto.d.ts +8 -4
- package/dist/index.d.ts +272 -26
- package/dist/index.js +7798 -5008
- package/dist/index.js.map +1 -1
- package/dist/lossless-columns.d.ts +58 -0
- package/dist/lossless-json.d.ts +39 -0
- package/dist/memory-domain.d.ts +3 -6
- package/dist/persistence-errors.d.ts +7 -14
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +2 -2
- package/dist/schema.d.ts +1420 -271
- package/dist/schema.js +25 -1
- package/dist/session-realtime-terminal.d.ts +7 -0
- package/dist/transcription-recordings-schema.d.ts +1264 -0
- package/dist/transcription-recordings.d.ts +228 -0
- package/drizzle/0065_enrollment_credential_generation.sql +10 -0
- package/drizzle/0140_retained_screenshot_artifacts.sql +192 -0
- package/drizzle/0170_resumable_transcription_recordings.sql +440 -0
- package/drizzle/0175_resumable_transcription_provider_deadline.sql +24 -0
- package/drizzle/0176_lossless_canonical_json.sql +975 -0
- package/drizzle/0177_session_events_workspace_turn_type_index.sql +5 -0
- package/drizzle/0178_permissioned_secret_reads.sql +14 -0
- package/drizzle/0179_slack_private_shortcut_delivery_gate.sql +85 -0
- package/drizzle/0180_retained_screenshot_lifecycle_fences.sql +273 -0
- package/drizzle/0181_connected_machine_removal.sql +52 -0
- package/drizzle/0182_connected_machine_remove_session_default.sql +77 -0
- package/package.json +4 -4
- package/src/database.ts +7 -1
- package/src/environment-crypto.ts +22 -9
- package/src/index.ts +4368 -1678
- package/src/lossless-columns.ts +35 -0
- package/src/lossless-json.ts +322 -0
- package/src/memory-domain.ts +5 -44
- package/src/persistence-errors.ts +29 -34
- package/src/runtime-posture.ts +14 -0
- package/src/schema.ts +264 -42
- package/src/session-control.ts +125 -76
- package/src/session-queue-commands.ts +325 -234
- package/src/session-realtime-context.ts +18 -5
- package/src/session-realtime-ledger.ts +29 -7
- package/src/session-realtime-mirror.ts +4 -2
- package/src/session-realtime-terminal.ts +89 -21
- package/src/session-realtime.ts +3 -2
- package/src/session-tool-call-settlement.ts +29 -15
- package/src/transcription-recordings-schema.ts +253 -0
- package/src/transcription-recordings.ts +1538 -0
- package/dist/chunk-JYQPJ6Y5.js.map +0 -1
- package/dist/chunk-RPHPNVWW.js.map +0 -1
- package/dist/event-payload-sanitizer.d.ts +0 -32
- package/src/event-payload-sanitizer.ts +0 -377
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
import { losslessCodecVersion, losslessText } from "./lossless-columns";
|
|
3
|
+
import {
|
|
4
|
+
boolean,
|
|
5
|
+
check,
|
|
6
|
+
index,
|
|
7
|
+
integer,
|
|
8
|
+
jsonb,
|
|
9
|
+
pgTable,
|
|
10
|
+
primaryKey,
|
|
11
|
+
text,
|
|
12
|
+
timestamp,
|
|
13
|
+
uniqueIndex,
|
|
14
|
+
uuid,
|
|
15
|
+
} from "drizzle-orm/pg-core";
|
|
16
|
+
|
|
17
|
+
export const transcriptionRecordingStateValues = [
|
|
18
|
+
"uploading",
|
|
19
|
+
"segmenting",
|
|
20
|
+
"ready",
|
|
21
|
+
"transcribing",
|
|
22
|
+
"complete",
|
|
23
|
+
"failed",
|
|
24
|
+
"discarded",
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
export const transcriptionRecordingChunkStateValues = ["uploading", "complete"] as const;
|
|
28
|
+
export const transcriptionRecordingObjectKindValues = ["chunk", "segment"] as const;
|
|
29
|
+
|
|
30
|
+
export const transcriptionRecordingSegmentStateValues = [
|
|
31
|
+
"preparing",
|
|
32
|
+
"pending",
|
|
33
|
+
"transcribing",
|
|
34
|
+
"complete",
|
|
35
|
+
"failed",
|
|
36
|
+
] as const;
|
|
37
|
+
|
|
38
|
+
export const transcriptionRecordings = pgTable(
|
|
39
|
+
"transcription_recordings",
|
|
40
|
+
{
|
|
41
|
+
id: uuid("id").primaryKey(),
|
|
42
|
+
accountId: uuid("account_id").notNull(),
|
|
43
|
+
workspaceId: uuid("workspace_id").notNull(),
|
|
44
|
+
subjectId: text("subject_id").notNull(),
|
|
45
|
+
mimeType: text("mime_type").notNull(),
|
|
46
|
+
state: text("state", { enum: transcriptionRecordingStateValues })
|
|
47
|
+
.notNull()
|
|
48
|
+
.default("uploading"),
|
|
49
|
+
nextChunkNumber: integer("next_chunk_number").notNull().default(0),
|
|
50
|
+
chunkCount: integer("chunk_count").notNull().default(0),
|
|
51
|
+
totalBytes: integer("total_bytes").notNull().default(0),
|
|
52
|
+
totalDurationMilliseconds: integer("total_duration_milliseconds").notNull().default(0),
|
|
53
|
+
segmentCount: integer("segment_count").notNull().default(0),
|
|
54
|
+
completedSegmentCount: integer("completed_segment_count").notNull().default(0),
|
|
55
|
+
transcriptText: losslessText("transcript_text"),
|
|
56
|
+
transcriptTextCodecVersion: losslessCodecVersion("transcript_text_codec_version"),
|
|
57
|
+
languages: jsonb("languages").$type<string[]>().notNull().default([]),
|
|
58
|
+
errorCode: text("error_code"),
|
|
59
|
+
retryable: boolean("retryable").notNull().default(false),
|
|
60
|
+
providerId: text("provider_id"),
|
|
61
|
+
processingGeneration: integer("processing_generation").notNull().default(0),
|
|
62
|
+
processingOwner: uuid("processing_owner"),
|
|
63
|
+
processingStartedAt: timestamp("processing_started_at", { withTimezone: true }),
|
|
64
|
+
objectsCleanedAt: timestamp("objects_cleaned_at", { withTimezone: true }),
|
|
65
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
66
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
67
|
+
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
|
|
68
|
+
},
|
|
69
|
+
(table) => ({
|
|
70
|
+
exactAuthority: uniqueIndex("transcription_recordings_exact_authority_uq").on(
|
|
71
|
+
table.accountId,
|
|
72
|
+
table.workspaceId,
|
|
73
|
+
table.subjectId,
|
|
74
|
+
table.id,
|
|
75
|
+
),
|
|
76
|
+
subjectCreated: index("transcription_recordings_subject_created_idx").on(
|
|
77
|
+
table.workspaceId,
|
|
78
|
+
table.subjectId,
|
|
79
|
+
table.createdAt,
|
|
80
|
+
),
|
|
81
|
+
expiry: index("transcription_recordings_expiry_idx").on(table.expiresAt, table.id),
|
|
82
|
+
valuesValid: check(
|
|
83
|
+
"transcription_recordings_values_check",
|
|
84
|
+
sql`${table.nextChunkNumber} >= 0
|
|
85
|
+
and ${table.chunkCount} >= 0
|
|
86
|
+
and ${table.totalBytes} >= 0
|
|
87
|
+
and ${table.totalDurationMilliseconds} >= 0
|
|
88
|
+
and ${table.segmentCount} >= 0
|
|
89
|
+
and ${table.completedSegmentCount} >= 0
|
|
90
|
+
and ${table.completedSegmentCount} <= ${table.segmentCount}
|
|
91
|
+
and octet_length(${table.subjectId}) between 1 and 1024
|
|
92
|
+
and octet_length(${table.mimeType}) between 1 and 128
|
|
93
|
+
and (
|
|
94
|
+
${table.providerId} is null
|
|
95
|
+
or octet_length(${table.providerId}) between 1 and 128
|
|
96
|
+
)`,
|
|
97
|
+
),
|
|
98
|
+
processingValid: check(
|
|
99
|
+
"transcription_recordings_processing_check",
|
|
100
|
+
sql`(
|
|
101
|
+
${table.processingOwner} is null
|
|
102
|
+
and ${table.processingStartedAt} is null
|
|
103
|
+
) or (
|
|
104
|
+
${table.processingOwner} is not null
|
|
105
|
+
and ${table.processingStartedAt} is not null
|
|
106
|
+
)`,
|
|
107
|
+
),
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
export const transcriptionRecordingObjects = pgTable(
|
|
112
|
+
"transcription_recording_objects",
|
|
113
|
+
{
|
|
114
|
+
accountId: uuid("account_id").notNull(),
|
|
115
|
+
workspaceId: uuid("workspace_id").notNull(),
|
|
116
|
+
subjectId: text("subject_id").notNull(),
|
|
117
|
+
recordingId: uuid("recording_id").notNull(),
|
|
118
|
+
objectKey: text("object_key").primaryKey(),
|
|
119
|
+
kind: text("kind", { enum: transcriptionRecordingObjectKindValues }).notNull(),
|
|
120
|
+
cleanupAfter: timestamp("cleanup_after", { withTimezone: true }).notNull(),
|
|
121
|
+
cleanupClaimId: uuid("cleanup_claim_id"),
|
|
122
|
+
cleanupClaimedAt: timestamp("cleanup_claimed_at", { withTimezone: true }),
|
|
123
|
+
cleanedAt: timestamp("cleaned_at", { withTimezone: true }),
|
|
124
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
125
|
+
},
|
|
126
|
+
(table) => ({
|
|
127
|
+
dueCleanup: index("transcription_recording_objects_due_cleanup_idx")
|
|
128
|
+
.on(table.cleanupAfter, table.objectKey)
|
|
129
|
+
.where(sql`${table.cleanedAt} is null`),
|
|
130
|
+
claimRecovery: index("transcription_recording_objects_claim_recovery_idx")
|
|
131
|
+
.on(table.cleanupClaimedAt, table.objectKey)
|
|
132
|
+
.where(sql`${table.cleanedAt} is null and ${table.cleanupClaimId} is not null`),
|
|
133
|
+
valuesValid: check(
|
|
134
|
+
"transcription_recording_objects_values_check",
|
|
135
|
+
sql`octet_length(${table.objectKey}) between 1 and 1024
|
|
136
|
+
and (
|
|
137
|
+
(${table.cleanupClaimId} is null and ${table.cleanupClaimedAt} is null)
|
|
138
|
+
or (${table.cleanupClaimId} is not null and ${table.cleanupClaimedAt} is not null)
|
|
139
|
+
)
|
|
140
|
+
and (
|
|
141
|
+
${table.cleanedAt} is null
|
|
142
|
+
or (${table.cleanupClaimId} is null and ${table.cleanupClaimedAt} is null)
|
|
143
|
+
)`,
|
|
144
|
+
),
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
export const transcriptionRecordingChunks = pgTable(
|
|
149
|
+
"transcription_recording_chunks",
|
|
150
|
+
{
|
|
151
|
+
accountId: uuid("account_id").notNull(),
|
|
152
|
+
workspaceId: uuid("workspace_id").notNull(),
|
|
153
|
+
subjectId: text("subject_id").notNull(),
|
|
154
|
+
recordingId: uuid("recording_id").notNull(),
|
|
155
|
+
chunkNumber: integer("chunk_number").notNull(),
|
|
156
|
+
state: text("state", { enum: transcriptionRecordingChunkStateValues })
|
|
157
|
+
.notNull()
|
|
158
|
+
.default("uploading"),
|
|
159
|
+
byteLength: integer("byte_length").notNull(),
|
|
160
|
+
sha256: text("sha256").notNull(),
|
|
161
|
+
startMilliseconds: integer("start_milliseconds").notNull(),
|
|
162
|
+
durationMilliseconds: integer("duration_milliseconds").notNull(),
|
|
163
|
+
objectKey: text("object_key").notNull(),
|
|
164
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
165
|
+
completedAt: timestamp("completed_at", { withTimezone: true }),
|
|
166
|
+
},
|
|
167
|
+
(table) => ({
|
|
168
|
+
pk: primaryKey({
|
|
169
|
+
name: "transcription_recording_chunks_pk",
|
|
170
|
+
columns: [table.recordingId, table.chunkNumber],
|
|
171
|
+
}),
|
|
172
|
+
recordingOrder: index("transcription_recording_chunks_order_idx").on(
|
|
173
|
+
table.workspaceId,
|
|
174
|
+
table.recordingId,
|
|
175
|
+
table.chunkNumber,
|
|
176
|
+
),
|
|
177
|
+
objectKey: uniqueIndex("transcription_recording_chunks_object_key_uq").on(table.objectKey),
|
|
178
|
+
valuesValid: check(
|
|
179
|
+
"transcription_recording_chunks_values_check",
|
|
180
|
+
sql`${table.chunkNumber} >= 0
|
|
181
|
+
and ${table.byteLength} > 0
|
|
182
|
+
and ${table.startMilliseconds} >= 0
|
|
183
|
+
and ${table.durationMilliseconds} >= 0
|
|
184
|
+
and ${table.sha256} ~ '^[0-9a-f]{64}$'
|
|
185
|
+
and octet_length(${table.objectKey}) between 1 and 1024
|
|
186
|
+
and (
|
|
187
|
+
(${table.state} = 'uploading' and ${table.completedAt} is null)
|
|
188
|
+
or (${table.state} = 'complete' and ${table.completedAt} is not null)
|
|
189
|
+
)`,
|
|
190
|
+
),
|
|
191
|
+
}),
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
export const transcriptionRecordingSegments = pgTable(
|
|
195
|
+
"transcription_recording_segments",
|
|
196
|
+
{
|
|
197
|
+
accountId: uuid("account_id").notNull(),
|
|
198
|
+
workspaceId: uuid("workspace_id").notNull(),
|
|
199
|
+
subjectId: text("subject_id").notNull(),
|
|
200
|
+
recordingId: uuid("recording_id").notNull(),
|
|
201
|
+
segmentNumber: integer("segment_number").notNull(),
|
|
202
|
+
generation: integer("generation").notNull(),
|
|
203
|
+
state: text("state", { enum: transcriptionRecordingSegmentStateValues })
|
|
204
|
+
.notNull()
|
|
205
|
+
.default("preparing"),
|
|
206
|
+
byteLength: integer("byte_length").notNull(),
|
|
207
|
+
sha256: text("sha256").notNull(),
|
|
208
|
+
startMilliseconds: integer("start_milliseconds").notNull(),
|
|
209
|
+
durationMilliseconds: integer("duration_milliseconds").notNull(),
|
|
210
|
+
objectKey: text("object_key").notNull(),
|
|
211
|
+
attemptId: uuid("attempt_id"),
|
|
212
|
+
attemptStartedAt: timestamp("attempt_started_at", { withTimezone: true }),
|
|
213
|
+
attemptDeadlineAt: timestamp("attempt_deadline_at", { withTimezone: true }),
|
|
214
|
+
transcriptText: losslessText("transcript_text"),
|
|
215
|
+
transcriptTextCodecVersion: losslessCodecVersion("transcript_text_codec_version"),
|
|
216
|
+
languages: jsonb("languages").$type<string[]>().notNull().default([]),
|
|
217
|
+
providerId: text("provider_id"),
|
|
218
|
+
errorCode: text("error_code"),
|
|
219
|
+
retryable: boolean("retryable").notNull().default(false),
|
|
220
|
+
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
|
|
221
|
+
updatedAt: timestamp("updated_at", { withTimezone: true }).notNull().defaultNow(),
|
|
222
|
+
},
|
|
223
|
+
(table) => ({
|
|
224
|
+
pk: primaryKey({
|
|
225
|
+
name: "transcription_recording_segments_pk",
|
|
226
|
+
columns: [table.recordingId, table.segmentNumber],
|
|
227
|
+
}),
|
|
228
|
+
recordingOrder: index("transcription_recording_segments_order_idx").on(
|
|
229
|
+
table.workspaceId,
|
|
230
|
+
table.recordingId,
|
|
231
|
+
table.segmentNumber,
|
|
232
|
+
),
|
|
233
|
+
objectKey: uniqueIndex("transcription_recording_segments_object_key_uq").on(table.objectKey),
|
|
234
|
+
valuesValid: check(
|
|
235
|
+
"transcription_recording_segments_values_check",
|
|
236
|
+
sql`${table.segmentNumber} >= 0
|
|
237
|
+
and ${table.generation} > 0
|
|
238
|
+
and ${table.byteLength} > 0
|
|
239
|
+
and ${table.startMilliseconds} >= 0
|
|
240
|
+
and ${table.durationMilliseconds} > 0
|
|
241
|
+
and ${table.sha256} ~ '^[0-9a-f]{64}$'
|
|
242
|
+
and octet_length(${table.objectKey}) between 1 and 1024
|
|
243
|
+
and (
|
|
244
|
+
(${table.attemptId} is null
|
|
245
|
+
and ${table.attemptStartedAt} is null
|
|
246
|
+
and ${table.attemptDeadlineAt} is null)
|
|
247
|
+
or (${table.attemptId} is not null
|
|
248
|
+
and ${table.attemptStartedAt} is not null
|
|
249
|
+
and ${table.attemptDeadlineAt} is not null)
|
|
250
|
+
)`,
|
|
251
|
+
),
|
|
252
|
+
}),
|
|
253
|
+
);
|