@opengeni/db 3.7.4 → 3.8.2-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/automations.d.ts +4 -0
- package/dist/canonical-human-identities.js +3 -3
- package/dist/{chunk-O56DM5GZ.js → chunk-53A2PEHT.js} +328 -31
- package/dist/chunk-53A2PEHT.js.map +1 -0
- package/dist/{chunk-SZAWDXQC.js → chunk-5S4BQAHX.js} +3 -3
- package/dist/{chunk-S3TDDCS2.js → chunk-CITYUGMW.js} +3 -3
- package/dist/{chunk-4NAR7FBA.js → chunk-F5YOZEYQ.js} +49 -1
- package/dist/chunk-F5YOZEYQ.js.map +1 -0
- package/dist/{chunk-F6PBS6WE.js → chunk-HZV7O6JR.js} +2 -2
- package/dist/{chunk-5NNCGFQY.js → chunk-RLQVPOVR.js} +2 -2
- package/dist/{chunk-DZCYW2WT.js → chunk-UKOGHUGC.js} +2 -2
- package/dist/{chunk-US4IS6IV.js → chunk-X6TO5HII.js} +2 -2
- package/dist/{chunk-U4WPPEBH.js → chunk-Y53WEFYB.js} +2 -2
- package/dist/connection-token-resolver.d.ts +4 -0
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/index.d.ts +164 -14
- package/dist/index.js +7327 -5442
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +9 -0
- package/dist/managed-auth-session-sets.js +3 -3
- package/dist/model-catalog.d.ts +153 -0
- package/dist/new-session-drafts.d.ts +12 -0
- package/dist/organization-membership-lifecycle.d.ts +8 -1
- package/dist/organization-model-providers.d.ts +101 -0
- package/dist/pack-components.d.ts +1 -0
- package/dist/pr-review.d.ts +9 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +7 -7
- package/dist/schema.d.ts +989 -2
- package/dist/schema.js +11 -1
- package/dist/session-background-commands.js +3 -3
- package/dist/session-control.d.ts +35 -0
- package/dist/session-queue-commands.d.ts +17 -0
- package/dist/session-tenancy.js +3 -3
- package/dist/video-generation.js +3 -3
- package/dist/xai-subscription.d.ts +8 -0
- package/drizzle/0387_bound_host_export_session_payloads.sql +165 -0
- package/drizzle/0388_sandbox_provider_deadline_interactions.sql +491 -0
- package/drizzle/0389_model_catalog_and_gateway_custom_models.sql +241 -0
- package/drizzle/0390_organization_model_provider_connections.sql +197 -0
- package/drizzle/0391_sandbox_provider_deadline_interaction_followup.sql +295 -0
- package/drizzle/0392_context_compaction_pending_observability.sql +198 -0
- package/drizzle/0393_workspace_memory_and_learning_defaults.sql +102 -0
- package/drizzle/0394_session_selected_skill_activation.sql +20 -0
- package/drizzle/0395_scheduled_task_unclaimed_occurrence_invalidation.sql +154 -0
- package/drizzle/0396_model_call_equivalent_credit_cost.sql +28 -0
- package/drizzle/0397_sandbox_deadline_rotation_preemption.sql +113 -0
- package/drizzle/0398_organization_workspace_management_entry.sql +206 -0
- package/drizzle/0399_additional_managed_organization_creation.sql +691 -0
- package/package.json +6 -6
- package/src/automations.ts +9 -1
- package/src/connection-token-resolver.ts +12 -0
- package/src/index.ts +1551 -272
- package/src/insights-model-bundle.ts +54 -5
- package/src/insights.ts +53 -7
- package/src/model-catalog.ts +682 -0
- package/src/new-session-drafts.ts +66 -21
- package/src/organization-membership-lifecycle.ts +47 -5
- package/src/organization-model-providers.ts +614 -0
- package/src/pack-components.ts +15 -2
- package/src/pr-review.ts +19 -0
- package/src/provision-roles.ts +2 -0
- package/src/runtime-posture.ts +48 -0
- package/src/schema.ts +348 -32
- package/src/session-control.ts +170 -0
- package/src/session-queue-commands.ts +157 -82
- package/src/xai-subscription.ts +66 -14
- package/dist/chunk-4NAR7FBA.js.map +0 -1
- package/dist/chunk-O56DM5GZ.js.map +0 -1
- /package/dist/{chunk-SZAWDXQC.js.map → chunk-5S4BQAHX.js.map} +0 -0
- /package/dist/{chunk-S3TDDCS2.js.map → chunk-CITYUGMW.js.map} +0 -0
- /package/dist/{chunk-F6PBS6WE.js.map → chunk-HZV7O6JR.js.map} +0 -0
- /package/dist/{chunk-5NNCGFQY.js.map → chunk-RLQVPOVR.js.map} +0 -0
- /package/dist/{chunk-DZCYW2WT.js.map → chunk-UKOGHUGC.js.map} +0 -0
- /package/dist/{chunk-US4IS6IV.js.map → chunk-X6TO5HII.js.map} +0 -0
- /package/dist/{chunk-U4WPPEBH.js.map → chunk-Y53WEFYB.js.map} +0 -0
package/dist/schema.js
CHANGED
|
@@ -62,6 +62,7 @@ import {
|
|
|
62
62
|
connectorActionPolicies,
|
|
63
63
|
connectorActionRequests,
|
|
64
64
|
creditLedgerEntries,
|
|
65
|
+
deploymentModelCatalog,
|
|
65
66
|
deviceEnrollmentRequests,
|
|
66
67
|
deviceEnrollmentStatusValues,
|
|
67
68
|
documentBases,
|
|
@@ -169,6 +170,9 @@ import {
|
|
|
169
170
|
organizationMembershipLifecycleEvents,
|
|
170
171
|
organizationMembershipOperationReceipts,
|
|
171
172
|
organizationMemberships,
|
|
173
|
+
organizationModelProviderConnectionOperations,
|
|
174
|
+
organizationModelProviderConnections,
|
|
175
|
+
organizationModelProviderCustomModels,
|
|
172
176
|
organizationPrivateSessionSettingEvents,
|
|
173
177
|
organizationPrivateSessionSettings,
|
|
174
178
|
organizationProfileEvents,
|
|
@@ -310,6 +314,7 @@ import {
|
|
|
310
314
|
workspaceCaptures,
|
|
311
315
|
workspaceCodexSubscriptionPreferences,
|
|
312
316
|
workspaceControlEvents,
|
|
317
|
+
workspaceGatewayCustomModels,
|
|
313
318
|
workspaceInferenceControls,
|
|
314
319
|
workspaceInstructionPolicyActivationEvents,
|
|
315
320
|
workspaceInstructionPolicyDeactivationEvents,
|
|
@@ -337,7 +342,7 @@ import {
|
|
|
337
342
|
xaiRotationSettings,
|
|
338
343
|
xaiSessionAccountPins,
|
|
339
344
|
xaiSubscriptionCredentials
|
|
340
|
-
} from "./chunk-
|
|
345
|
+
} from "./chunk-53A2PEHT.js";
|
|
341
346
|
import "./chunk-PZ5AY32C.js";
|
|
342
347
|
export {
|
|
343
348
|
agentRunStates,
|
|
@@ -403,6 +408,7 @@ export {
|
|
|
403
408
|
connectorActionPolicies,
|
|
404
409
|
connectorActionRequests,
|
|
405
410
|
creditLedgerEntries,
|
|
411
|
+
deploymentModelCatalog,
|
|
406
412
|
deviceEnrollmentRequests,
|
|
407
413
|
deviceEnrollmentStatusValues,
|
|
408
414
|
documentBases,
|
|
@@ -510,6 +516,9 @@ export {
|
|
|
510
516
|
organizationMembershipLifecycleEvents,
|
|
511
517
|
organizationMembershipOperationReceipts,
|
|
512
518
|
organizationMemberships,
|
|
519
|
+
organizationModelProviderConnectionOperations,
|
|
520
|
+
organizationModelProviderConnections,
|
|
521
|
+
organizationModelProviderCustomModels,
|
|
513
522
|
organizationPrivateSessionSettingEvents,
|
|
514
523
|
organizationPrivateSessionSettings,
|
|
515
524
|
organizationProfileEvents,
|
|
@@ -651,6 +660,7 @@ export {
|
|
|
651
660
|
workspaceCaptures,
|
|
652
661
|
workspaceCodexSubscriptionPreferences,
|
|
653
662
|
workspaceControlEvents,
|
|
663
|
+
workspaceGatewayCustomModels,
|
|
654
664
|
workspaceInferenceControls,
|
|
655
665
|
workspaceInstructionPolicyActivationEvents,
|
|
656
666
|
workspaceInstructionPolicyDeactivationEvents,
|
|
@@ -12,9 +12,9 @@ import {
|
|
|
12
12
|
settleClaimedConnectedMachineBackgroundCommand,
|
|
13
13
|
settleConnectedMachineSessionBackgroundCommand,
|
|
14
14
|
settleSessionBackgroundCommandForRetainedProcess
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
17
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-CITYUGMW.js";
|
|
16
|
+
import "./chunk-HZV7O6JR.js";
|
|
17
|
+
import "./chunk-53A2PEHT.js";
|
|
18
18
|
import "./chunk-PZ5AY32C.js";
|
|
19
19
|
export {
|
|
20
20
|
backgroundCommandActivityForSessions,
|
|
@@ -429,6 +429,40 @@ export declare function evaluateSessionControl(db: Database, workspaceId: string
|
|
|
429
429
|
lock?: WorkspaceControlLockMode;
|
|
430
430
|
workspaceControl?: WorkspaceControlRow | undefined;
|
|
431
431
|
}): Promise<EffectiveSessionControl>;
|
|
432
|
+
export type SessionPromptCommandAction = "prompt.send" | "prompt.steer";
|
|
433
|
+
/**
|
|
434
|
+
* Prompt operation keys are actor-scoped across target sessions and across the
|
|
435
|
+
* Send/Steer action pair. The advisory lock closes the gap left by the legacy
|
|
436
|
+
* action/target-specific unique index without changing old receipt identities.
|
|
437
|
+
*/
|
|
438
|
+
export declare function reserveSessionPromptCommandReceipt(db: Database, input: {
|
|
439
|
+
accountId: string;
|
|
440
|
+
workspaceId: string;
|
|
441
|
+
actor: SessionCommandActor;
|
|
442
|
+
action: SessionPromptCommandAction;
|
|
443
|
+
targetSessionId: string;
|
|
444
|
+
operationKey: string;
|
|
445
|
+
canonicalRequestHash: string;
|
|
446
|
+
boundaryRequestHash: string;
|
|
447
|
+
}): Promise<{
|
|
448
|
+
receipt: SessionCommandReceiptRow;
|
|
449
|
+
replay: boolean;
|
|
450
|
+
}>;
|
|
451
|
+
/** Serialize one actor-scoped prompt operation before replay or reservation. */
|
|
452
|
+
export declare function lockSessionPromptCommandOperation(db: Database, input: {
|
|
453
|
+
workspaceId: string;
|
|
454
|
+
actor: SessionCommandActor;
|
|
455
|
+
operationKey: string;
|
|
456
|
+
}): Promise<void>;
|
|
457
|
+
/** Return only a fully committed exact prompt receipt with the new boundary fingerprint. */
|
|
458
|
+
export declare function getCompletedSessionPromptCommandReceipt(db: Database, input: {
|
|
459
|
+
workspaceId: string;
|
|
460
|
+
actor: SessionCommandActor;
|
|
461
|
+
action: SessionPromptCommandAction;
|
|
462
|
+
targetSessionId: string;
|
|
463
|
+
operationKey: string;
|
|
464
|
+
boundaryRequestHash: string;
|
|
465
|
+
}): Promise<SessionCommandReceiptRow | null>;
|
|
432
466
|
export declare function reserveSessionCommandReceipt(db: Database, input: {
|
|
433
467
|
accountId: string;
|
|
434
468
|
workspaceId: string;
|
|
@@ -439,6 +473,7 @@ export declare function reserveSessionCommandReceipt(db: Database, input: {
|
|
|
439
473
|
operationKey: string;
|
|
440
474
|
canonicalRequestHash: string;
|
|
441
475
|
identityScope?: "actor" | "goal_operation";
|
|
476
|
+
initialResult?: Record<string, unknown>;
|
|
442
477
|
}): Promise<{
|
|
443
478
|
receipt: SessionCommandReceiptRow;
|
|
444
479
|
replay: boolean;
|
|
@@ -53,6 +53,18 @@ export type SubmitHumanPromptResult = {
|
|
|
53
53
|
workspaceControlEventId: string | null;
|
|
54
54
|
replay: boolean;
|
|
55
55
|
};
|
|
56
|
+
export declare function replaySubmittedHumanPromptFromBoundaryReceipt(db: Database, input: {
|
|
57
|
+
workspaceId: string;
|
|
58
|
+
sessionId: string;
|
|
59
|
+
subjectId: string;
|
|
60
|
+
actor: SessionCommandActor;
|
|
61
|
+
operationKey: string;
|
|
62
|
+
delivery: "send" | "steer";
|
|
63
|
+
boundaryRequestHash: string;
|
|
64
|
+
expectedDraftRevision?: number | null;
|
|
65
|
+
/** Wait for an overlapping same-key transaction before checking committed replay truth. */
|
|
66
|
+
serializeOperation?: boolean;
|
|
67
|
+
}): Promise<SubmitHumanPromptResult | null>;
|
|
56
68
|
export type AgentInternalUpdateCommandResult = {
|
|
57
69
|
receipt: SessionCommandReceiptRow;
|
|
58
70
|
updateId: string;
|
|
@@ -179,6 +191,8 @@ export declare function submitHumanPromptInTransaction(db: SessionActivityDataba
|
|
|
179
191
|
subjectLabel?: string;
|
|
180
192
|
actor: SessionCommandActor;
|
|
181
193
|
operationKey: string;
|
|
194
|
+
/** Stable parsed boundary-request identity used before mutable enrichment. */
|
|
195
|
+
boundaryRequestHash?: string;
|
|
182
196
|
delivery: "send" | "steer";
|
|
183
197
|
controlEtag?: string | null;
|
|
184
198
|
expectedDraftRevision?: number | null;
|
|
@@ -213,6 +227,9 @@ export declare function submitHumanPromptInTransaction(db: SessionActivityDataba
|
|
|
213
227
|
id: string;
|
|
214
228
|
headersEncrypted: Record<string, string>;
|
|
215
229
|
}>;
|
|
230
|
+
/** Trusted database-only admission seam. It runs only after a completed
|
|
231
|
+
* operation replay has been ruled out; throwing rolls the prompt back. */
|
|
232
|
+
beforeFreshPromptCommit?: (tx: Database) => Promise<void>;
|
|
216
233
|
/** Request-scoped callers bound the control prefix wait; lifecycle callers omit it. */
|
|
217
234
|
controlLockTimeoutMs?: number;
|
|
218
235
|
}): Promise<SubmitHumanPromptResult>;
|
package/dist/session-tenancy.js
CHANGED
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
replayAppliedSessionFork,
|
|
15
15
|
sessionTenancyProductActivated,
|
|
16
16
|
transitionSessionVisibility
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-
|
|
19
|
-
import "./chunk-
|
|
17
|
+
} from "./chunk-RLQVPOVR.js";
|
|
18
|
+
import "./chunk-HZV7O6JR.js";
|
|
19
|
+
import "./chunk-53A2PEHT.js";
|
|
20
20
|
import "./chunk-PZ5AY32C.js";
|
|
21
21
|
export {
|
|
22
22
|
SessionTenancyAccessError,
|
package/dist/video-generation.js
CHANGED
|
@@ -29,9 +29,9 @@ import {
|
|
|
29
29
|
settleVideoGenerationFailure,
|
|
30
30
|
settleVideoGenerationReady,
|
|
31
31
|
updateWorkspaceVideoGenerationPolicy
|
|
32
|
-
} from "./chunk-
|
|
33
|
-
import "./chunk-
|
|
34
|
-
import "./chunk-
|
|
32
|
+
} from "./chunk-5S4BQAHX.js";
|
|
33
|
+
import "./chunk-HZV7O6JR.js";
|
|
34
|
+
import "./chunk-53A2PEHT.js";
|
|
35
35
|
import "./chunk-PZ5AY32C.js";
|
|
36
36
|
export {
|
|
37
37
|
ACTIVE_VIDEO_GENERATION_STATUSES,
|
|
@@ -97,6 +97,14 @@ export declare function listXaiSubscriptionAccountsMetadata(db: Database, input:
|
|
|
97
97
|
export declare function workspaceXaiSubscriptionActive(db: Database, settings: {
|
|
98
98
|
readonly supergrokSubscriptionEnabled: boolean;
|
|
99
99
|
}, workspaceId: string, subjectId: string): Promise<boolean>;
|
|
100
|
+
/** Metadata-only readiness for the exact provider-account authority frozen on a turn. */
|
|
101
|
+
export declare function workspaceXaiSubscriptionActiveForAuthority(db: Database, settings: {
|
|
102
|
+
readonly supergrokSubscriptionEnabled: boolean;
|
|
103
|
+
}, input: {
|
|
104
|
+
workspaceId: string;
|
|
105
|
+
subjectId: string;
|
|
106
|
+
authoritySnapshot: XaiAuthoritySnapshot;
|
|
107
|
+
}): Promise<boolean>;
|
|
100
108
|
export declare function getXaiSubscriptionAccountMetadata(db: Database, input: {
|
|
101
109
|
workspaceId: string;
|
|
102
110
|
subjectId: string;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- Host export is an optional bounded projection. Canonical session_events keeps
|
|
3
|
+
-- the complete lossless payload; an oversized projection must never roll back
|
|
4
|
+
-- the source event or a later lifecycle transaction that closes pending work.
|
|
5
|
+
|
|
6
|
+
SET lock_timeout = '5s';
|
|
7
|
+
SET statement_timeout = '10min';
|
|
8
|
+
|
|
9
|
+
DO $migration$
|
|
10
|
+
DECLARE target_schema text := current_schema();
|
|
11
|
+
BEGIN
|
|
12
|
+
EXECUTE format($create$
|
|
13
|
+
CREATE OR REPLACE FUNCTION opengeni_private.enqueue_host_session_event_export()
|
|
14
|
+
RETURNS trigger
|
|
15
|
+
LANGUAGE plpgsql
|
|
16
|
+
SECURITY DEFINER
|
|
17
|
+
SET search_path = pg_catalog
|
|
18
|
+
AS $function$
|
|
19
|
+
DECLARE
|
|
20
|
+
v_enabled boolean;
|
|
21
|
+
v_initiator jsonb;
|
|
22
|
+
v_context jsonb := '{}'::jsonb;
|
|
23
|
+
v_origin text;
|
|
24
|
+
v_source_payload_bytes integer;
|
|
25
|
+
v_export_payload jsonb;
|
|
26
|
+
v_export_payload_codec_version smallint;
|
|
27
|
+
v_payload_bytes integer;
|
|
28
|
+
BEGIN
|
|
29
|
+
IF NEW.type IN (
|
|
30
|
+
'agent.message.delta', 'agent.reasoning.delta',
|
|
31
|
+
'sandbox.command.output.delta', 'terminal.pty.output.delta'
|
|
32
|
+
) THEN
|
|
33
|
+
RETURN NEW;
|
|
34
|
+
END IF;
|
|
35
|
+
|
|
36
|
+
SELECT c.session_events_enabled INTO v_enabled
|
|
37
|
+
FROM %1$I.host_export_config c WHERE c.id = 1
|
|
38
|
+
FOR SHARE;
|
|
39
|
+
IF coalesce(v_enabled, false) = false THEN
|
|
40
|
+
RETURN NEW;
|
|
41
|
+
END IF;
|
|
42
|
+
|
|
43
|
+
IF NEW.turn_id IS NOT NULL THEN
|
|
44
|
+
SELECT
|
|
45
|
+
CASE WHEN octet_length(t.initiator_subject_id) <= 1024 THEN
|
|
46
|
+
jsonb_strip_nulls(jsonb_build_object(
|
|
47
|
+
'kind', t.initiator_kind,
|
|
48
|
+
'subjectId', t.initiator_subject_id,
|
|
49
|
+
'label', CASE
|
|
50
|
+
WHEN jsonb_typeof(t.initiator_context -> 'label') = 'string'
|
|
51
|
+
THEN left(t.initiator_context ->> 'label', 256)
|
|
52
|
+
ELSE NULL
|
|
53
|
+
END
|
|
54
|
+
))
|
|
55
|
+
ELSE NULL END,
|
|
56
|
+
jsonb_strip_nulls(jsonb_build_object(
|
|
57
|
+
'label', CASE
|
|
58
|
+
WHEN jsonb_typeof(t.initiator_context -> 'label') = 'string'
|
|
59
|
+
THEN left(t.initiator_context ->> 'label', 256)
|
|
60
|
+
ELSE NULL
|
|
61
|
+
END,
|
|
62
|
+
'backfill', CASE
|
|
63
|
+
WHEN jsonb_typeof(t.initiator_context -> 'backfill') = 'boolean'
|
|
64
|
+
THEN t.initiator_context -> 'backfill'
|
|
65
|
+
ELSE NULL
|
|
66
|
+
END,
|
|
67
|
+
'attributionOmitted', CASE
|
|
68
|
+
WHEN octet_length(t.initiator_subject_id) > 1024 THEN 'subject_id_too_large'
|
|
69
|
+
ELSE NULL
|
|
70
|
+
END
|
|
71
|
+
)),
|
|
72
|
+
t.source
|
|
73
|
+
INTO v_initiator, v_context, v_origin
|
|
74
|
+
FROM %1$I.session_turns t
|
|
75
|
+
WHERE t.workspace_id = NEW.workspace_id AND t.id = NEW.turn_id;
|
|
76
|
+
ELSIF NEW.type = 'session.created' THEN
|
|
77
|
+
SELECT
|
|
78
|
+
CASE WHEN octet_length(s.created_by_subject_id) <= 1024 THEN
|
|
79
|
+
jsonb_strip_nulls(jsonb_build_object(
|
|
80
|
+
'kind', s.created_by_kind,
|
|
81
|
+
'subjectId', s.created_by_subject_id,
|
|
82
|
+
'label', CASE
|
|
83
|
+
WHEN jsonb_typeof(s.created_by_context -> 'label') = 'string'
|
|
84
|
+
THEN left(s.created_by_context ->> 'label', 256)
|
|
85
|
+
ELSE NULL
|
|
86
|
+
END
|
|
87
|
+
))
|
|
88
|
+
ELSE NULL END,
|
|
89
|
+
jsonb_strip_nulls(jsonb_build_object(
|
|
90
|
+
'label', CASE
|
|
91
|
+
WHEN jsonb_typeof(s.created_by_context -> 'label') = 'string'
|
|
92
|
+
THEN left(s.created_by_context ->> 'label', 256)
|
|
93
|
+
ELSE NULL
|
|
94
|
+
END,
|
|
95
|
+
'backfill', CASE
|
|
96
|
+
WHEN jsonb_typeof(s.created_by_context -> 'backfill') = 'boolean'
|
|
97
|
+
THEN s.created_by_context -> 'backfill'
|
|
98
|
+
ELSE NULL
|
|
99
|
+
END,
|
|
100
|
+
'attributionOmitted', CASE
|
|
101
|
+
WHEN octet_length(s.created_by_subject_id) > 1024 THEN 'subject_id_too_large'
|
|
102
|
+
ELSE NULL
|
|
103
|
+
END
|
|
104
|
+
)),
|
|
105
|
+
NULL
|
|
106
|
+
INTO v_initiator, v_context, v_origin
|
|
107
|
+
FROM %1$I.sessions s
|
|
108
|
+
WHERE s.workspace_id = NEW.workspace_id AND s.id = NEW.session_id;
|
|
109
|
+
END IF;
|
|
110
|
+
|
|
111
|
+
v_source_payload_bytes := octet_length(NEW.payload::text);
|
|
112
|
+
v_export_payload := NEW.payload;
|
|
113
|
+
v_export_payload_codec_version := NEW.payload_codec_version;
|
|
114
|
+
IF v_source_payload_bytes > 65536 THEN
|
|
115
|
+
v_export_payload := jsonb_build_object(
|
|
116
|
+
'_hostExport', jsonb_build_object(
|
|
117
|
+
'payloadMode', 'summary',
|
|
118
|
+
'payloadTruncated', true,
|
|
119
|
+
'originalBytes', v_source_payload_bytes,
|
|
120
|
+
'sourceEventId', NEW.id,
|
|
121
|
+
'fullPayload', 'retained in canonical session event'
|
|
122
|
+
),
|
|
123
|
+
'preview', '[host-export payload omitted at bounded projection boundary]'
|
|
124
|
+
);
|
|
125
|
+
-- The projection is literal PostgreSQL JSON, not an application-codec
|
|
126
|
+
-- envelope. Preserve codec truth only when the original payload is kept.
|
|
127
|
+
v_export_payload_codec_version := NULL;
|
|
128
|
+
END IF;
|
|
129
|
+
|
|
130
|
+
v_payload_bytes := octet_length(v_export_payload::text)
|
|
131
|
+
+ octet_length(NEW.type)
|
|
132
|
+
+ coalesce(octet_length(NEW.client_event_id), 0)
|
|
133
|
+
+ coalesce(octet_length(NEW.turn_association), 0)
|
|
134
|
+
+ coalesce(octet_length(NEW.duplicate_reason), 0)
|
|
135
|
+
+ octet_length(coalesce(v_initiator, 'null'::jsonb)::text)
|
|
136
|
+
+ octet_length(v_context::text)
|
|
137
|
+
+ 768;
|
|
138
|
+
INSERT INTO %1$I.host_export_outbox (
|
|
139
|
+
export_kind, source_id, account_id, workspace_id, session_id,
|
|
140
|
+
turn_id, turn_generation, turn_attempt_id, session_sequence,
|
|
141
|
+
client_event_id, turn_association, duplicate_of_event_id, duplicate_reason,
|
|
142
|
+
event_type, idempotency_key, initiator, initiator_context, origin,
|
|
143
|
+
payload, payload_codec_version, envelope_bytes, occurred_at,
|
|
144
|
+
source_recorded_at, enqueued_at
|
|
145
|
+
) VALUES (
|
|
146
|
+
'session_event', NEW.id, NEW.account_id, NEW.workspace_id, NEW.session_id,
|
|
147
|
+
NEW.turn_id, NEW.turn_generation, NEW.turn_attempt_id, NEW.sequence,
|
|
148
|
+
NEW.client_event_id, NEW.turn_association, NEW.duplicate_of_event_id,
|
|
149
|
+
NEW.duplicate_reason,
|
|
150
|
+
NEW.type, 'session_event:' || NEW.id::text, v_initiator,
|
|
151
|
+
coalesce(v_context, '{}'::jsonb), v_origin, v_export_payload,
|
|
152
|
+
v_export_payload_codec_version, greatest(1, v_payload_bytes), NEW.occurred_at,
|
|
153
|
+
NEW.created_at, clock_timestamp()
|
|
154
|
+
)
|
|
155
|
+
ON CONFLICT (export_kind, source_id) DO NOTHING;
|
|
156
|
+
RETURN NEW;
|
|
157
|
+
END $function$;
|
|
158
|
+
$create$, target_schema);
|
|
159
|
+
END
|
|
160
|
+
$migration$;
|
|
161
|
+
|
|
162
|
+
COMMENT ON COLUMN host_export_outbox.payload IS
|
|
163
|
+
'Immutable bounded host projection. Canonical session_events retains the complete payload; oversized host projections carry an explicit content-free truncation receipt.';
|
|
164
|
+
COMMENT ON COLUMN host_export_outbox.payload_codec_version IS
|
|
165
|
+
'Codec truth for the stored host projection. NULL means literal SQL JSON, including oversized-payload projections; 1 means the original application-coded payload was retained exactly.';
|