@opengeni/db 0.31.1 → 0.36.1
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/browser-auth.d.ts +209 -1
- package/dist/browser-downloads.d.ts +51 -0
- package/dist/browser-identities.d.ts +11 -2
- package/dist/browser-sessions.d.ts +83 -1
- package/dist/browser-state-artifacts.d.ts +75 -1
- package/dist/canonical-human-identities.d.ts +48 -0
- package/dist/canonical-human-identities.js +28 -0
- package/dist/canonical-human-identities.js.map +1 -0
- package/dist/capability-integrations.d.ts +8 -6
- package/dist/{chunk-MWDVXQOL.js → chunk-5KTIEDX7.js} +5773 -4212
- package/dist/chunk-5KTIEDX7.js.map +1 -0
- package/dist/chunk-FPVAD4CO.js +117 -0
- package/dist/chunk-FPVAD4CO.js.map +1 -0
- package/dist/chunk-GYO7ED2Q.js +259 -0
- package/dist/chunk-GYO7ED2Q.js.map +1 -0
- package/dist/{chunk-F5FT7BEZ.js → chunk-HSOWSYOX.js} +2 -2
- package/dist/{chunk-YHZXQ7HP.js → chunk-VKLB2ZGI.js} +446 -19
- package/dist/chunk-VKLB2ZGI.js.map +1 -0
- package/dist/{chunk-NBE6CHRI.js → chunk-VTPRIXKG.js} +49 -9
- package/dist/chunk-VTPRIXKG.js.map +1 -0
- package/dist/{chunk-ISI2TIUG.js → chunk-Z7VYMNPZ.js} +76 -4
- package/dist/chunk-Z7VYMNPZ.js.map +1 -0
- package/dist/database.d.ts +5 -0
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/index.d.ts +467 -29
- package/dist/index.js +23247 -16232
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +23 -7
- package/dist/integration-bindings.d.ts +24 -24
- package/dist/integration-facets.d.ts +99 -0
- package/dist/interaction-revisions.d.ts +11 -0
- package/dist/interaction-schema.d.ts +698 -34
- package/dist/persistence-errors.d.ts +8 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +8 -7
- package/dist/schema.d.ts +9464 -5412
- package/dist/schema.js +51 -9
- package/dist/session-control.d.ts +29 -3
- package/dist/session-tenancy.d.ts +44 -0
- package/dist/session-tenancy.js +16 -0
- package/dist/session-tenancy.js.map +1 -0
- package/dist/slack-task-policy-schema.d.ts +847 -0
- package/dist/slack-task-policy.d.ts +65 -0
- package/dist/task-notes-schema.d.ts +924 -0
- package/dist/task-notes.d.ts +85 -0
- package/dist/video-generation.d.ts +9 -0
- package/dist/video-generation.js +5 -3
- package/dist/xai-subscription.d.ts +326 -0
- package/drizzle/0212_browser_state_transfer_hardening.sql +560 -0
- package/drizzle/0213_browser_interaction_authority.sql +67 -0
- package/drizzle/0214_browser_download_saves.sql +34 -0
- package/drizzle/0215_browser_controller_host.sql +385 -0
- package/drizzle/0216_browser_auth_health_evidence.sql +137 -0
- package/drizzle/0217_external_browser_auth_operations.sql +22 -0
- package/drizzle/0218_organization_tenancy_foundation.sql +299 -0
- package/drizzle/0219_organization_tenancy_managed_human_provisioning.sql +317 -0
- package/drizzle/0219_site_auth_maintenance_sessions.sql +234 -0
- package/drizzle/0220_memory_slack_append_only_cascade.sql +38 -0
- package/drizzle/0220_session_channels.sql +54 -0
- package/drizzle/0221_sessions_channel_index.sql +5 -0
- package/drizzle/0222_session_visibility_authority_epochs.sql +158 -0
- package/drizzle/0222_sessions_channel_fk.sql +89 -0
- package/drizzle/0223_pending_tool_event_output.sql +55 -0
- package/drizzle/0223_sessions_channel_fk_validate.sql +118 -0
- package/drizzle/0224_slack_post_outcome_reconciliation.sql +123 -0
- package/drizzle/0225_session_visibility_fork_activation.sql +1363 -0
- package/drizzle/0226_personal_codex_authority_foundation.sql +365 -0
- package/drizzle/0227_slack_native_actions.sql +145 -0
- package/drizzle/0228_interaction_controller_data_plane.sql +14 -0
- package/drizzle/0228_slack_task_policy.sql +400 -0
- package/drizzle/0229_slack_inbox_file_fact.sql +10 -0
- package/drizzle/0230_user_scoped_variable_sets_rigs.sql +84 -0
- package/drizzle/0231_integration_definition_identity_cutover.sql +271 -0
- package/drizzle/0232_integration_facet_authority_cutover.sql +610 -0
- package/drizzle/0233_skill_and_integration_authority_cutover.sql +1162 -0
- package/drizzle/0234_xai_subscription_authority.sql +1139 -0
- package/drizzle/0235_canonical_human_login_bindings.sql +920 -0
- package/drizzle/0236_browser_identity_lifecycle.sql +39 -0
- package/drizzle/0236_session_visibility_slack_policy.sql +72 -0
- package/drizzle/0237_interaction_transition_reaper.sql +263 -0
- package/drizzle/0238_goal_persistence_policy.sql +471 -0
- package/drizzle/0238_recover_unclaimed_session_turns.sql +307 -0
- package/drizzle/0238_supergrok_realtime_model.sql +29 -0
- package/drizzle/0239_supergrok_video_funding.sql +50 -0
- package/drizzle/0239_task_tree_notes.sql +990 -0
- package/package.json +13 -5
- package/src/browser-auth.ts +2600 -123
- package/src/browser-downloads.ts +517 -0
- package/src/browser-identities.ts +220 -3
- package/src/browser-sessions.ts +334 -45
- package/src/browser-state-artifacts.ts +402 -12
- package/src/canonical-human-identities.ts +317 -0
- package/src/capability-integrations.ts +121 -213
- package/src/database.ts +41 -1
- package/src/index.ts +4625 -411
- package/src/insights.ts +109 -28
- package/src/integration-bindings.ts +101 -101
- package/src/{integration-features.ts → integration-facets.ts} +187 -184
- package/src/interaction-revisions.ts +33 -3
- package/src/interaction-schema.ts +311 -8
- package/src/pack-components.ts +43 -43
- package/src/pack-installations.ts +0 -43
- package/src/persistence-errors.ts +60 -1
- package/src/plugin-packages.ts +9 -9
- package/src/provision-roles.ts +232 -0
- package/src/runtime-posture.ts +227 -14
- package/src/schema.ts +1188 -75
- package/src/session-control.ts +122 -37
- package/src/session-queue-commands.ts +78 -1
- package/src/session-tenancy.ts +188 -0
- package/src/session-tool-call-settlement.ts +9 -3
- package/src/slack-task-policy-schema.ts +130 -0
- package/src/slack-task-policy.ts +341 -0
- package/src/task-notes-schema.ts +135 -0
- package/src/task-notes.ts +178 -0
- package/src/video-generation.ts +90 -12
- package/src/workspace-artifacts.ts +1 -1
- package/src/xai-subscription.ts +1887 -0
- package/dist/chunk-ISI2TIUG.js.map +0 -1
- package/dist/chunk-MWDVXQOL.js.map +0 -1
- package/dist/chunk-NBE6CHRI.js.map +0 -1
- package/dist/chunk-YHZXQ7HP.js.map +0 -1
- package/dist/integration-features.d.ts +0 -99
- /package/dist/{chunk-F5FT7BEZ.js.map → chunk-HSOWSYOX.js.map} +0 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- Add the inert, expand-only personal Codex provider-account authority
|
|
3
|
+
-- foundation. Existing credentials and accepted work are explicitly
|
|
4
|
+
-- workspace-scoped. No runtime path discovers, creates, selects, leases,
|
|
5
|
+
-- materializes, consumes, or reports a user-scoped credential in this slice.
|
|
6
|
+
|
|
7
|
+
SET LOCAL lock_timeout = '5s';
|
|
8
|
+
SET LOCAL statement_timeout = '10min';
|
|
9
|
+
|
|
10
|
+
-- Stable tuple lookup for the credential-side validation trigger. This adds no
|
|
11
|
+
-- privilege and does not change the FORCE-RLS lifecycle of the authority table.
|
|
12
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "organization_user_resource_authorities_codex_tuple_idx"
|
|
13
|
+
ON "organization_user_resource_authorities" (
|
|
14
|
+
"id",
|
|
15
|
+
"account_id",
|
|
16
|
+
"organization_membership_id",
|
|
17
|
+
"resource_kind",
|
|
18
|
+
"resource_id",
|
|
19
|
+
"generation"
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
ALTER TABLE "codex_subscription_credentials"
|
|
23
|
+
ADD COLUMN "authority_scope" text,
|
|
24
|
+
ADD COLUMN "owner_organization_membership_id" uuid,
|
|
25
|
+
ADD COLUMN "organization_user_resource_authority_id" uuid,
|
|
26
|
+
ADD COLUMN "organization_user_resource_kind" text,
|
|
27
|
+
ADD COLUMN "organization_user_resource_authority_generation" bigint;
|
|
28
|
+
|
|
29
|
+
-- This UPDATE is intentionally explicit rather than relying on an ADD COLUMN
|
|
30
|
+
-- default: every pre-foundation provider account is classified workspace-only.
|
|
31
|
+
UPDATE "codex_subscription_credentials"
|
|
32
|
+
SET "authority_scope" = 'workspace'
|
|
33
|
+
WHERE "authority_scope" IS NULL;
|
|
34
|
+
|
|
35
|
+
ALTER TABLE "codex_subscription_credentials"
|
|
36
|
+
ALTER COLUMN "authority_scope" SET DEFAULT 'workspace',
|
|
37
|
+
ALTER COLUMN "authority_scope" SET NOT NULL,
|
|
38
|
+
ADD CONSTRAINT "codex_credentials_authority_scope_chk" CHECK (
|
|
39
|
+
"authority_scope" IN ('workspace', 'user')
|
|
40
|
+
) NOT VALID,
|
|
41
|
+
ADD CONSTRAINT "codex_credentials_authority_shape_chk" CHECK (
|
|
42
|
+
(
|
|
43
|
+
"authority_scope" = 'workspace'
|
|
44
|
+
AND "owner_organization_membership_id" IS NULL
|
|
45
|
+
AND "organization_user_resource_authority_id" IS NULL
|
|
46
|
+
AND "organization_user_resource_kind" IS NULL
|
|
47
|
+
AND "organization_user_resource_authority_generation" IS NULL
|
|
48
|
+
) OR (
|
|
49
|
+
"authority_scope" = 'user'
|
|
50
|
+
AND "owner_organization_membership_id" IS NOT NULL
|
|
51
|
+
AND "organization_user_resource_authority_id" IS NOT NULL
|
|
52
|
+
AND "organization_user_resource_kind" = 'codex_subscription'
|
|
53
|
+
AND "organization_user_resource_authority_generation" IS NOT NULL
|
|
54
|
+
AND "organization_user_resource_authority_generation" > 0
|
|
55
|
+
)
|
|
56
|
+
) NOT VALID,
|
|
57
|
+
ADD CONSTRAINT "codex_credentials_owner_membership_fk"
|
|
58
|
+
FOREIGN KEY ("owner_organization_membership_id", "account_id")
|
|
59
|
+
REFERENCES "organization_memberships"("id", "account_id")
|
|
60
|
+
ON DELETE RESTRICT NOT VALID,
|
|
61
|
+
ADD CONSTRAINT "codex_credentials_user_authority_fk"
|
|
62
|
+
FOREIGN KEY (
|
|
63
|
+
"organization_user_resource_authority_id",
|
|
64
|
+
"account_id",
|
|
65
|
+
"owner_organization_membership_id",
|
|
66
|
+
"organization_user_resource_kind",
|
|
67
|
+
"id",
|
|
68
|
+
"organization_user_resource_authority_generation"
|
|
69
|
+
)
|
|
70
|
+
REFERENCES "organization_user_resource_authorities"(
|
|
71
|
+
"id",
|
|
72
|
+
"account_id",
|
|
73
|
+
"organization_membership_id",
|
|
74
|
+
"resource_kind",
|
|
75
|
+
"resource_id",
|
|
76
|
+
"generation"
|
|
77
|
+
)
|
|
78
|
+
ON DELETE RESTRICT NOT VALID;
|
|
79
|
+
|
|
80
|
+
ALTER TABLE "codex_subscription_credentials"
|
|
81
|
+
VALIDATE CONSTRAINT "codex_credentials_authority_scope_chk",
|
|
82
|
+
VALIDATE CONSTRAINT "codex_credentials_authority_shape_chk",
|
|
83
|
+
VALIDATE CONSTRAINT "codex_credentials_owner_membership_fk",
|
|
84
|
+
VALIDATE CONSTRAINT "codex_credentials_user_authority_fk";
|
|
85
|
+
|
|
86
|
+
DO $personal_codex_authority_validation$
|
|
87
|
+
DECLARE
|
|
88
|
+
data_schema text := current_schema();
|
|
89
|
+
BEGIN
|
|
90
|
+
EXECUTE format($ddl$
|
|
91
|
+
CREATE OR REPLACE FUNCTION %1$I.validate_personal_codex_credential_authority()
|
|
92
|
+
RETURNS trigger
|
|
93
|
+
LANGUAGE plpgsql
|
|
94
|
+
AS $body$
|
|
95
|
+
DECLARE
|
|
96
|
+
exact_authority boolean;
|
|
97
|
+
BEGIN
|
|
98
|
+
IF NEW.authority_scope = 'workspace' THEN
|
|
99
|
+
RETURN NEW;
|
|
100
|
+
END IF;
|
|
101
|
+
|
|
102
|
+
-- Invoker rights are deliberate in this inert slice. The ordinary app
|
|
103
|
+
-- role has no direct visibility into either organization authority table,
|
|
104
|
+
-- so it cannot manufacture a user-scoped credential. A later activation
|
|
105
|
+
-- slice must introduce a separately reviewed narrow lifecycle capability.
|
|
106
|
+
SELECT true
|
|
107
|
+
INTO exact_authority
|
|
108
|
+
FROM %1$I.organization_memberships membership
|
|
109
|
+
INNER JOIN %1$I.organization_user_resource_authorities authority
|
|
110
|
+
ON authority.id = NEW.organization_user_resource_authority_id
|
|
111
|
+
AND authority.account_id = membership.account_id
|
|
112
|
+
AND authority.organization_membership_id = membership.id
|
|
113
|
+
WHERE membership.id = NEW.owner_organization_membership_id
|
|
114
|
+
AND membership.account_id = NEW.account_id
|
|
115
|
+
AND membership.status = 'active'
|
|
116
|
+
AND membership.revoked_at IS NULL
|
|
117
|
+
AND authority.resource_kind = 'codex_subscription'
|
|
118
|
+
AND authority.resource_id = NEW.id
|
|
119
|
+
AND authority.generation = NEW.organization_user_resource_authority_generation
|
|
120
|
+
AND authority.status = 'active'
|
|
121
|
+
AND authority.revoked_at IS NULL
|
|
122
|
+
FOR KEY SHARE OF membership, authority;
|
|
123
|
+
|
|
124
|
+
IF exact_authority IS DISTINCT FROM true THEN
|
|
125
|
+
RAISE EXCEPTION 'personal Codex credential authority tuple is invalid'
|
|
126
|
+
USING ERRCODE = '23514';
|
|
127
|
+
END IF;
|
|
128
|
+
RETURN NEW;
|
|
129
|
+
END;
|
|
130
|
+
$body$;
|
|
131
|
+
$ddl$, data_schema);
|
|
132
|
+
|
|
133
|
+
EXECUTE format(
|
|
134
|
+
'DROP TRIGGER IF EXISTS codex_credentials_validate_user_authority_trg ON %I.codex_subscription_credentials',
|
|
135
|
+
data_schema
|
|
136
|
+
);
|
|
137
|
+
EXECUTE format($ddl$
|
|
138
|
+
CREATE TRIGGER codex_credentials_validate_user_authority_trg
|
|
139
|
+
BEFORE INSERT OR UPDATE OF
|
|
140
|
+
id,
|
|
141
|
+
account_id,
|
|
142
|
+
authority_scope,
|
|
143
|
+
owner_organization_membership_id,
|
|
144
|
+
organization_user_resource_authority_id,
|
|
145
|
+
organization_user_resource_kind,
|
|
146
|
+
organization_user_resource_authority_generation
|
|
147
|
+
ON %1$I.codex_subscription_credentials
|
|
148
|
+
FOR EACH ROW
|
|
149
|
+
EXECUTE FUNCTION %1$I.validate_personal_codex_credential_authority()
|
|
150
|
+
$ddl$, data_schema);
|
|
151
|
+
END
|
|
152
|
+
$personal_codex_authority_validation$;
|
|
153
|
+
|
|
154
|
+
-- One strict identifier-free snapshot shape is shared by the accepted turn,
|
|
155
|
+
-- scheduled task, and internal-update boundaries. The user variant stores only
|
|
156
|
+
-- the positive authority generation; it is not executable authority by itself.
|
|
157
|
+
DO $codex_provider_account_snapshot_validator$
|
|
158
|
+
DECLARE
|
|
159
|
+
data_schema text := current_schema();
|
|
160
|
+
BEGIN
|
|
161
|
+
EXECUTE format($ddl$
|
|
162
|
+
CREATE OR REPLACE FUNCTION %1$I.codex_provider_account_authority_snapshot_v1_valid(
|
|
163
|
+
snapshot jsonb
|
|
164
|
+
)
|
|
165
|
+
RETURNS boolean
|
|
166
|
+
LANGUAGE sql
|
|
167
|
+
IMMUTABLE
|
|
168
|
+
STRICT
|
|
169
|
+
AS $body$
|
|
170
|
+
SELECT
|
|
171
|
+
snapshot = '{"version":1,"scope":"workspace"}'::jsonb
|
|
172
|
+
OR (
|
|
173
|
+
jsonb_typeof(snapshot) = 'object'
|
|
174
|
+
AND (SELECT count(*) FROM jsonb_object_keys(snapshot)) = 3
|
|
175
|
+
AND snapshot ?& ARRAY['version', 'scope', 'authorityGeneration']
|
|
176
|
+
AND snapshot -> 'version' = '1'::jsonb
|
|
177
|
+
AND snapshot ->> 'scope' = 'user'
|
|
178
|
+
AND jsonb_typeof(snapshot -> 'authorityGeneration') = 'number'
|
|
179
|
+
AND snapshot ->> 'authorityGeneration' ~ '^[1-9][0-9]*$'
|
|
180
|
+
AND (snapshot ->> 'authorityGeneration')::numeric <= 9007199254740991
|
|
181
|
+
)
|
|
182
|
+
$body$;
|
|
183
|
+
$ddl$, data_schema);
|
|
184
|
+
END
|
|
185
|
+
$codex_provider_account_snapshot_validator$;
|
|
186
|
+
|
|
187
|
+
ALTER TABLE "session_turns"
|
|
188
|
+
ADD COLUMN "codex_provider_account_authority_snapshot" jsonb;
|
|
189
|
+
ALTER TABLE "scheduled_tasks"
|
|
190
|
+
ADD COLUMN "codex_provider_account_authority_snapshot" jsonb;
|
|
191
|
+
ALTER TABLE "session_system_updates"
|
|
192
|
+
ADD COLUMN "codex_provider_account_authority_snapshot" jsonb;
|
|
193
|
+
ALTER TABLE "session_system_update_outbox"
|
|
194
|
+
ADD COLUMN "codex_provider_account_authority_snapshot" jsonb;
|
|
195
|
+
|
|
196
|
+
UPDATE "session_turns"
|
|
197
|
+
SET "codex_provider_account_authority_snapshot" = '{"version":1,"scope":"workspace"}'::jsonb
|
|
198
|
+
WHERE "codex_provider_account_authority_snapshot" IS NULL;
|
|
199
|
+
UPDATE "scheduled_tasks"
|
|
200
|
+
SET "codex_provider_account_authority_snapshot" = '{"version":1,"scope":"workspace"}'::jsonb
|
|
201
|
+
WHERE "codex_provider_account_authority_snapshot" IS NULL;
|
|
202
|
+
UPDATE "session_system_updates"
|
|
203
|
+
SET "codex_provider_account_authority_snapshot" = '{"version":1,"scope":"workspace"}'::jsonb
|
|
204
|
+
WHERE "codex_provider_account_authority_snapshot" IS NULL;
|
|
205
|
+
UPDATE "session_system_update_outbox"
|
|
206
|
+
SET "codex_provider_account_authority_snapshot" = '{"version":1,"scope":"workspace"}'::jsonb
|
|
207
|
+
WHERE "codex_provider_account_authority_snapshot" IS NULL;
|
|
208
|
+
|
|
209
|
+
ALTER TABLE "session_turns"
|
|
210
|
+
ALTER COLUMN "codex_provider_account_authority_snapshot"
|
|
211
|
+
SET DEFAULT '{"version":1,"scope":"workspace"}'::jsonb,
|
|
212
|
+
ALTER COLUMN "codex_provider_account_authority_snapshot" SET NOT NULL,
|
|
213
|
+
ADD CONSTRAINT "session_turns_codex_authority_snapshot_chk" CHECK (
|
|
214
|
+
codex_provider_account_authority_snapshot_v1_valid(
|
|
215
|
+
"codex_provider_account_authority_snapshot"
|
|
216
|
+
)
|
|
217
|
+
) NOT VALID;
|
|
218
|
+
ALTER TABLE "scheduled_tasks"
|
|
219
|
+
ALTER COLUMN "codex_provider_account_authority_snapshot"
|
|
220
|
+
SET DEFAULT '{"version":1,"scope":"workspace"}'::jsonb,
|
|
221
|
+
ALTER COLUMN "codex_provider_account_authority_snapshot" SET NOT NULL,
|
|
222
|
+
ADD CONSTRAINT "scheduled_tasks_codex_authority_snapshot_chk" CHECK (
|
|
223
|
+
codex_provider_account_authority_snapshot_v1_valid(
|
|
224
|
+
"codex_provider_account_authority_snapshot"
|
|
225
|
+
)
|
|
226
|
+
) NOT VALID;
|
|
227
|
+
ALTER TABLE "session_system_updates"
|
|
228
|
+
ALTER COLUMN "codex_provider_account_authority_snapshot"
|
|
229
|
+
SET DEFAULT '{"version":1,"scope":"workspace"}'::jsonb,
|
|
230
|
+
ALTER COLUMN "codex_provider_account_authority_snapshot" SET NOT NULL,
|
|
231
|
+
ADD CONSTRAINT "session_updates_codex_authority_snapshot_chk" CHECK (
|
|
232
|
+
codex_provider_account_authority_snapshot_v1_valid(
|
|
233
|
+
"codex_provider_account_authority_snapshot"
|
|
234
|
+
)
|
|
235
|
+
) NOT VALID;
|
|
236
|
+
ALTER TABLE "session_system_update_outbox"
|
|
237
|
+
ALTER COLUMN "codex_provider_account_authority_snapshot"
|
|
238
|
+
SET DEFAULT '{"version":1,"scope":"workspace"}'::jsonb,
|
|
239
|
+
ALTER COLUMN "codex_provider_account_authority_snapshot" SET NOT NULL,
|
|
240
|
+
ADD CONSTRAINT "system_update_outbox_codex_authority_snapshot_chk" CHECK (
|
|
241
|
+
codex_provider_account_authority_snapshot_v1_valid(
|
|
242
|
+
"codex_provider_account_authority_snapshot"
|
|
243
|
+
)
|
|
244
|
+
) NOT VALID;
|
|
245
|
+
|
|
246
|
+
ALTER TABLE "session_turns"
|
|
247
|
+
VALIDATE CONSTRAINT "session_turns_codex_authority_snapshot_chk";
|
|
248
|
+
ALTER TABLE "scheduled_tasks"
|
|
249
|
+
VALIDATE CONSTRAINT "scheduled_tasks_codex_authority_snapshot_chk";
|
|
250
|
+
ALTER TABLE "session_system_updates"
|
|
251
|
+
VALIDATE CONSTRAINT "session_updates_codex_authority_snapshot_chk";
|
|
252
|
+
ALTER TABLE "session_system_update_outbox"
|
|
253
|
+
VALIDATE CONSTRAINT "system_update_outbox_codex_authority_snapshot_chk";
|
|
254
|
+
|
|
255
|
+
DO $codex_provider_account_snapshot_immutability$
|
|
256
|
+
DECLARE
|
|
257
|
+
data_schema text := current_schema();
|
|
258
|
+
BEGIN
|
|
259
|
+
EXECUTE format($ddl$
|
|
260
|
+
CREATE OR REPLACE FUNCTION %1$I.prevent_codex_provider_account_authority_snapshot_mutation()
|
|
261
|
+
RETURNS trigger
|
|
262
|
+
LANGUAGE plpgsql
|
|
263
|
+
AS $body$
|
|
264
|
+
BEGIN
|
|
265
|
+
IF NEW.codex_provider_account_authority_snapshot
|
|
266
|
+
IS DISTINCT FROM OLD.codex_provider_account_authority_snapshot
|
|
267
|
+
THEN
|
|
268
|
+
RAISE EXCEPTION '%% Codex provider-account authority snapshot is immutable', TG_TABLE_NAME
|
|
269
|
+
USING ERRCODE = '23514';
|
|
270
|
+
END IF;
|
|
271
|
+
RETURN NEW;
|
|
272
|
+
END;
|
|
273
|
+
$body$;
|
|
274
|
+
$ddl$, data_schema);
|
|
275
|
+
|
|
276
|
+
EXECUTE format($ddl$
|
|
277
|
+
CREATE TRIGGER session_turns_codex_authority_snapshot_immutable_trg
|
|
278
|
+
BEFORE UPDATE OF codex_provider_account_authority_snapshot
|
|
279
|
+
ON %1$I.session_turns
|
|
280
|
+
FOR EACH ROW
|
|
281
|
+
EXECUTE FUNCTION %1$I.prevent_codex_provider_account_authority_snapshot_mutation()
|
|
282
|
+
$ddl$, data_schema);
|
|
283
|
+
EXECUTE format($ddl$
|
|
284
|
+
CREATE TRIGGER scheduled_tasks_codex_authority_snapshot_immutable_trg
|
|
285
|
+
BEFORE UPDATE OF codex_provider_account_authority_snapshot
|
|
286
|
+
ON %1$I.scheduled_tasks
|
|
287
|
+
FOR EACH ROW
|
|
288
|
+
EXECUTE FUNCTION %1$I.prevent_codex_provider_account_authority_snapshot_mutation()
|
|
289
|
+
$ddl$, data_schema);
|
|
290
|
+
EXECUTE format($ddl$
|
|
291
|
+
CREATE TRIGGER session_updates_codex_authority_snapshot_immutable_trg
|
|
292
|
+
BEFORE UPDATE OF codex_provider_account_authority_snapshot
|
|
293
|
+
ON %1$I.session_system_updates
|
|
294
|
+
FOR EACH ROW
|
|
295
|
+
EXECUTE FUNCTION %1$I.prevent_codex_provider_account_authority_snapshot_mutation()
|
|
296
|
+
$ddl$, data_schema);
|
|
297
|
+
EXECUTE format($ddl$
|
|
298
|
+
CREATE TRIGGER system_update_outbox_codex_authority_snapshot_immutable_trg
|
|
299
|
+
BEFORE UPDATE OF codex_provider_account_authority_snapshot
|
|
300
|
+
ON %1$I.session_system_update_outbox
|
|
301
|
+
FOR EACH ROW
|
|
302
|
+
EXECUTE FUNCTION %1$I.prevent_codex_provider_account_authority_snapshot_mutation()
|
|
303
|
+
$ddl$, data_schema);
|
|
304
|
+
END
|
|
305
|
+
$codex_provider_account_snapshot_immutability$;
|
|
306
|
+
|
|
307
|
+
-- Preserve the snapshot across the existing global child-result outbox claim.
|
|
308
|
+
-- Returning one additive column is rolling-safe for old consumers and gives a
|
|
309
|
+
-- future activation slice the exact stored boundary rather than a re-derived
|
|
310
|
+
-- ambient value.
|
|
311
|
+
DROP FUNCTION opengeni_private.claim_session_system_update_outbox(integer);
|
|
312
|
+
CREATE FUNCTION opengeni_private.claim_session_system_update_outbox(p_limit integer)
|
|
313
|
+
RETURNS TABLE (
|
|
314
|
+
id uuid, account_id uuid, workspace_id uuid, source_session_id uuid,
|
|
315
|
+
target_session_id uuid, dedupe_key text, kind text, classification text,
|
|
316
|
+
source_id text, summary text, summary_codec_version integer,
|
|
317
|
+
payload jsonb, payload_codec_version integer, lineage jsonb,
|
|
318
|
+
personal_connection_delegations jsonb,
|
|
319
|
+
codex_provider_account_authority_snapshot jsonb
|
|
320
|
+
)
|
|
321
|
+
LANGUAGE plpgsql
|
|
322
|
+
SECURITY DEFINER
|
|
323
|
+
AS $function$
|
|
324
|
+
BEGIN
|
|
325
|
+
RETURN QUERY
|
|
326
|
+
WITH claimed AS (
|
|
327
|
+
SELECT o.id FROM session_system_update_outbox o
|
|
328
|
+
WHERE o.status = 'pending'
|
|
329
|
+
ORDER BY o.created_at, o.id
|
|
330
|
+
FOR UPDATE SKIP LOCKED
|
|
331
|
+
LIMIT greatest(1, least(coalesce(p_limit, 100), 100))
|
|
332
|
+
)
|
|
333
|
+
UPDATE session_system_update_outbox o
|
|
334
|
+
SET attempts = o.attempts + 1, updated_at = now()
|
|
335
|
+
FROM claimed c WHERE o.id = c.id
|
|
336
|
+
RETURNING o.id, o.account_id, o.workspace_id, o.source_session_id,
|
|
337
|
+
o.target_session_id, o.dedupe_key, o.kind, o.classification,
|
|
338
|
+
o.source_id, o.summary, o.summary_codec_version,
|
|
339
|
+
o.payload, o.payload_codec_version, o.lineage,
|
|
340
|
+
o.personal_connection_delegations,
|
|
341
|
+
o.codex_provider_account_authority_snapshot;
|
|
342
|
+
END
|
|
343
|
+
$function$;
|
|
344
|
+
REVOKE ALL ON FUNCTION opengeni_private.claim_session_system_update_outbox(integer) FROM PUBLIC;
|
|
345
|
+
DO $system_update_outbox_role_grant$
|
|
346
|
+
BEGIN
|
|
347
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'opengeni_app') THEN
|
|
348
|
+
GRANT EXECUTE ON FUNCTION opengeni_private.claim_session_system_update_outbox(integer)
|
|
349
|
+
TO opengeni_app;
|
|
350
|
+
END IF;
|
|
351
|
+
END
|
|
352
|
+
$system_update_outbox_role_grant$;
|
|
353
|
+
|
|
354
|
+
COMMENT ON COLUMN "codex_subscription_credentials"."authority_scope" IS
|
|
355
|
+
'Explicit workspace/user ownership fact. Existing and ordinary runtime-created rows remain workspace.';
|
|
356
|
+
COMMENT ON COLUMN "codex_subscription_credentials"."connected_by_subject_id" IS
|
|
357
|
+
'Connection audit/redemption attribution only; never Codex credential ownership authority.';
|
|
358
|
+
COMMENT ON COLUMN "session_turns"."codex_provider_account_authority_snapshot" IS
|
|
359
|
+
'Opaque identifier-free Codex provider-account authority snapshot; inert until a later activation slice.';
|
|
360
|
+
COMMENT ON COLUMN "scheduled_tasks"."codex_provider_account_authority_snapshot" IS
|
|
361
|
+
'Opaque identifier-free Codex provider-account authority snapshot; legacy and current writers default workspace.';
|
|
362
|
+
COMMENT ON COLUMN "session_system_updates"."codex_provider_account_authority_snapshot" IS
|
|
363
|
+
'Opaque identifier-free Codex provider-account authority snapshot for an accepted internal update.';
|
|
364
|
+
COMMENT ON COLUMN "session_system_update_outbox"."codex_provider_account_authority_snapshot" IS
|
|
365
|
+
'Opaque identifier-free Codex provider-account authority snapshot for child-result delivery provenance.';
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
|
|
3
|
+
ALTER TABLE "slack_interactions"
|
|
4
|
+
ADD COLUMN "initiating_slack_user_id" text;
|
|
5
|
+
|
|
6
|
+
ALTER TABLE "slack_interaction_inbox"
|
|
7
|
+
DROP CONSTRAINT "slack_interaction_inbox_trigger_check";
|
|
8
|
+
|
|
9
|
+
ALTER TABLE "slack_interaction_inbox"
|
|
10
|
+
ADD CONSTRAINT "slack_interaction_inbox_trigger_check"
|
|
11
|
+
CHECK (
|
|
12
|
+
"trigger_kind" IN (
|
|
13
|
+
'app_mention', 'dm', 'reaction', 'slash_command',
|
|
14
|
+
'message_shortcut', 'thread_reply', 'block_action'
|
|
15
|
+
)
|
|
16
|
+
) NOT VALID;
|
|
17
|
+
|
|
18
|
+
ALTER TABLE "slack_interaction_inbox"
|
|
19
|
+
VALIDATE CONSTRAINT "slack_interaction_inbox_trigger_check";
|
|
20
|
+
|
|
21
|
+
ALTER TABLE "slack_interactions"
|
|
22
|
+
ADD CONSTRAINT "slack_interactions_initiating_user_check"
|
|
23
|
+
CHECK (
|
|
24
|
+
"initiating_slack_user_id" IS NULL
|
|
25
|
+
OR octet_length("initiating_slack_user_id") BETWEEN 1 AND 64
|
|
26
|
+
) NOT VALID;
|
|
27
|
+
|
|
28
|
+
ALTER TABLE "slack_interactions"
|
|
29
|
+
VALIDATE CONSTRAINT "slack_interactions_initiating_user_check";
|
|
30
|
+
|
|
31
|
+
CREATE TABLE "slack_interaction_action_handles" (
|
|
32
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
33
|
+
"account_id" uuid NOT NULL REFERENCES "managed_accounts"("id") ON DELETE CASCADE,
|
|
34
|
+
"workspace_id" uuid NOT NULL REFERENCES "workspaces"("id") ON DELETE CASCADE,
|
|
35
|
+
"connection_id" uuid NOT NULL REFERENCES "connections"("id") ON DELETE CASCADE,
|
|
36
|
+
"interaction_id" uuid NOT NULL,
|
|
37
|
+
"session_id" uuid NOT NULL REFERENCES "sessions"("id") ON DELETE CASCADE,
|
|
38
|
+
"session_event_sequence" integer NOT NULL,
|
|
39
|
+
"action_kind" text NOT NULL,
|
|
40
|
+
"action_key" text NOT NULL,
|
|
41
|
+
"target_id" text,
|
|
42
|
+
"target_value" text,
|
|
43
|
+
"authorized_subject_id" text NOT NULL,
|
|
44
|
+
"authorized_slack_user_id" text NOT NULL,
|
|
45
|
+
"message_operation_id" uuid NOT NULL,
|
|
46
|
+
"status" text NOT NULL DEFAULT 'pending',
|
|
47
|
+
"result" text,
|
|
48
|
+
"expires_at" timestamptz NOT NULL,
|
|
49
|
+
"completed_at" timestamptz,
|
|
50
|
+
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
51
|
+
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
|
52
|
+
CONSTRAINT "slack_interaction_action_handles_interaction_fk"
|
|
53
|
+
FOREIGN KEY ("account_id", "workspace_id", "interaction_id")
|
|
54
|
+
REFERENCES "slack_interactions"("account_id", "workspace_id", "id")
|
|
55
|
+
ON DELETE CASCADE,
|
|
56
|
+
CONSTRAINT "slack_interaction_action_handles_identity_uq"
|
|
57
|
+
UNIQUE ("interaction_id", "session_event_sequence", "action_key"),
|
|
58
|
+
CONSTRAINT "slack_interaction_action_handles_bounds_check" CHECK (
|
|
59
|
+
"session_event_sequence" >= 0
|
|
60
|
+
AND octet_length("action_kind") BETWEEN 1 AND 64
|
|
61
|
+
AND octet_length("action_key") BETWEEN 1 AND 512
|
|
62
|
+
AND ("target_id" IS NULL OR octet_length("target_id") BETWEEN 1 AND 512)
|
|
63
|
+
AND ("target_value" IS NULL OR octet_length("target_value") BETWEEN 1 AND 1024)
|
|
64
|
+
AND octet_length("authorized_subject_id") BETWEEN 1 AND 512
|
|
65
|
+
AND octet_length("authorized_slack_user_id") BETWEEN 1 AND 64
|
|
66
|
+
AND "action_kind" IN (
|
|
67
|
+
'approval_approve', 'approval_reject', 'human_input_select',
|
|
68
|
+
'human_input_skip', 'session_status', 'session_pause', 'session_resume'
|
|
69
|
+
)
|
|
70
|
+
AND "status" IN ('pending', 'completed', 'stale')
|
|
71
|
+
AND ("result" IS NULL OR octet_length("result") BETWEEN 1 AND 64)
|
|
72
|
+
AND (
|
|
73
|
+
("status" = 'pending' AND "result" IS NULL AND "completed_at" IS NULL)
|
|
74
|
+
OR ("status" IN ('completed', 'stale') AND "result" IS NOT NULL AND "completed_at" IS NOT NULL)
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
CREATE INDEX "slack_interaction_action_handles_pending_idx"
|
|
80
|
+
ON "slack_interaction_action_handles" ("workspace_id", "status", "expires_at", "id");
|
|
81
|
+
|
|
82
|
+
CREATE TABLE "slack_bot_update_operations" (
|
|
83
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
84
|
+
"account_id" uuid NOT NULL REFERENCES "managed_accounts"("id") ON DELETE CASCADE,
|
|
85
|
+
"workspace_id" uuid NOT NULL REFERENCES "workspaces"("id") ON DELETE CASCADE,
|
|
86
|
+
"connection_id" uuid NOT NULL REFERENCES "connections"("id") ON DELETE CASCADE,
|
|
87
|
+
"operation_id" uuid NOT NULL,
|
|
88
|
+
"slack_channel_id" text NOT NULL,
|
|
89
|
+
"slack_message_timestamp" text NOT NULL,
|
|
90
|
+
"request_digest" text NOT NULL,
|
|
91
|
+
"status" text NOT NULL,
|
|
92
|
+
"claim_holder_id" uuid,
|
|
93
|
+
"claim_expires_at" timestamptz,
|
|
94
|
+
"attempt_count" integer NOT NULL DEFAULT 0,
|
|
95
|
+
"last_failure_code" text,
|
|
96
|
+
"completed_at" timestamptz,
|
|
97
|
+
"created_at" timestamptz NOT NULL DEFAULT now(),
|
|
98
|
+
"updated_at" timestamptz NOT NULL DEFAULT now(),
|
|
99
|
+
CONSTRAINT "slack_bot_update_operations_workspace_operation_uq"
|
|
100
|
+
UNIQUE ("workspace_id", "connection_id", "operation_id"),
|
|
101
|
+
CONSTRAINT "slack_bot_update_operations_bounds_check" CHECK (
|
|
102
|
+
octet_length("slack_channel_id") BETWEEN 1 AND 64
|
|
103
|
+
AND octet_length("slack_message_timestamp") BETWEEN 1 AND 64
|
|
104
|
+
AND "request_digest" ~ '^[0-9a-f]{64}$'
|
|
105
|
+
AND "status" IN ('provider_started', 'completed')
|
|
106
|
+
AND "attempt_count" > 0
|
|
107
|
+
AND (("claim_holder_id" IS NULL) = ("claim_expires_at" IS NULL))
|
|
108
|
+
AND (
|
|
109
|
+
("status" = 'provider_started' AND "completed_at" IS NULL)
|
|
110
|
+
OR (
|
|
111
|
+
"status" = 'completed'
|
|
112
|
+
AND "claim_holder_id" IS NULL
|
|
113
|
+
AND "claim_expires_at" IS NULL
|
|
114
|
+
AND "completed_at" IS NOT NULL
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
CREATE INDEX "slack_bot_update_operations_workspace_status_idx"
|
|
121
|
+
ON "slack_bot_update_operations" ("workspace_id", "status", "updated_at");
|
|
122
|
+
|
|
123
|
+
ALTER TABLE "slack_interaction_action_handles" ENABLE ROW LEVEL SECURITY;
|
|
124
|
+
ALTER TABLE "slack_interaction_action_handles" FORCE ROW LEVEL SECURITY;
|
|
125
|
+
ALTER TABLE "slack_bot_update_operations" ENABLE ROW LEVEL SECURITY;
|
|
126
|
+
ALTER TABLE "slack_bot_update_operations" FORCE ROW LEVEL SECURITY;
|
|
127
|
+
|
|
128
|
+
CREATE POLICY workspace_isolation ON "slack_interaction_action_handles"
|
|
129
|
+
USING (opengeni_private.workspace_rls_visible("account_id", "workspace_id"))
|
|
130
|
+
WITH CHECK (opengeni_private.workspace_rls_visible("account_id", "workspace_id"));
|
|
131
|
+
|
|
132
|
+
CREATE POLICY workspace_isolation ON "slack_bot_update_operations"
|
|
133
|
+
USING (opengeni_private.workspace_rls_visible("account_id", "workspace_id"))
|
|
134
|
+
WITH CHECK (opengeni_private.workspace_rls_visible("account_id", "workspace_id"));
|
|
135
|
+
|
|
136
|
+
DO $$
|
|
137
|
+
BEGIN
|
|
138
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'opengeni_app') THEN
|
|
139
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE
|
|
140
|
+
"slack_interaction_action_handles",
|
|
141
|
+
"slack_bot_update_operations"
|
|
142
|
+
TO opengeni_app;
|
|
143
|
+
END IF;
|
|
144
|
+
END
|
|
145
|
+
$$;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- Cache browserd's provider tunnel separately from desktop and terminal. The
|
|
3
|
+
-- cache is nullable for rolling compatibility and is always fenced by the
|
|
4
|
+
-- lease's epoch + provider instance before publication/use.
|
|
5
|
+
|
|
6
|
+
ALTER TABLE "sandbox_leases"
|
|
7
|
+
ADD COLUMN IF NOT EXISTS "controller_data_plane_url" text;
|
|
8
|
+
|
|
9
|
+
DO $$
|
|
10
|
+
BEGIN
|
|
11
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'opengeni_app') THEN
|
|
12
|
+
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE sandbox_leases TO opengeni_app;
|
|
13
|
+
END IF;
|
|
14
|
+
END $$;
|