@opengeni/db 0.7.3 → 0.9.3
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-B22X3IEZ.js → chunk-4LG5NBTC.js} +512 -32
- package/dist/chunk-4LG5NBTC.js.map +1 -0
- package/dist/{chunk-YFQ7SGE4.js → chunk-BMFDXFPA.js} +23 -1
- package/dist/chunk-BMFDXFPA.js.map +1 -0
- package/dist/chunk-KW526IJA.js +127 -0
- package/dist/chunk-KW526IJA.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6068 -2090
- package/dist/index.js.map +1 -1
- package/dist/migrate.d.ts +29 -4
- package/dist/migrate.js +3 -1
- package/dist/provision-roles.d.ts +721 -46
- package/dist/provision-roles.js +1 -1
- package/dist/{schema-BN5mB9xZ.d.ts → schema-CdPGTHlD.d.ts} +2118 -119
- package/dist/schema.d.ts +1 -1
- package/dist/schema.js +17 -1
- package/drizzle/0064_rotation_strategy_sharded_backfill.sql +15 -0
- package/drizzle/0065_session_attempt_quiescence.sql +26 -0
- package/drizzle/0066_session_interruption_attempt_lookup.sql +4 -0
- package/drizzle/0067_session_event_payload_bounds.sql +209 -0
- package/drizzle/0068_workspace_control_event_bounds.sql +134 -0
- package/drizzle/0069_session_event_history_backfill.sql +32 -0
- package/drizzle/0070_session_event_type_sequence_lookup.sql +4 -0
- package/drizzle/0071_session_event_monitoring_tail.sql +10 -0
- package/drizzle/0072_sessions_workspace_created_id_idx.sql +4 -0
- package/drizzle/0073_sessions_workspace_updated_id_idx.sql +4 -0
- package/drizzle/0074_session_activity_revisions.sql +72 -0
- package/drizzle/0075_sessions_workspace_activity_revision_idx.sql +4 -0
- package/drizzle/0076_session_workflow_wake_acl.sql +13 -0
- package/drizzle/0077_session_attempt_latest_lookup.sql +4 -0
- package/drizzle/0094_quarantine_credential_bearing_catalog_urls.sql +51 -0
- package/drizzle/0095_github_existing_installations.sql +84 -0
- package/drizzle/0096_session_turn_initiators.sql +97 -0
- package/drizzle/0097_host_export_outbox.sql +1220 -0
- package/drizzle/0098_usage_events_workspace_session_idx.sql +4 -0
- package/drizzle/0099_session_human_input_attempt_owner_index.sql +6 -0
- package/drizzle/0100_session_human_input_requests.sql +89 -0
- package/drizzle/0101_session_mcp_connection_refs.sql +30 -0
- package/drizzle/0102_session_command_receipt_service_actor.sql +16 -0
- package/drizzle/0103_host_export_root_session.sql +166 -0
- package/drizzle/0104_host_export_root_session_backfill.sql +27 -0
- package/drizzle/0105_session_turn_instructions.sql +9 -0
- package/package.json +4 -4
- package/src/connection-token-resolver.ts +287 -1
- package/src/event-payload-sanitizer.ts +57 -19
- package/src/index.ts +5377 -1125
- package/src/memory-domain.ts +1 -1
- package/src/migrate.ts +86 -23
- package/src/persistence-errors.ts +252 -0
- package/src/provision-roles.ts +42 -0
- package/src/schema.ts +552 -34
- package/src/session-control.ts +518 -38
- package/src/session-queue-commands.ts +308 -57
- package/src/session-tool-call-settlement.ts +58 -7
- package/src/turn-initiator.ts +155 -0
- package/dist/chunk-7LDU7F5P.js +0 -80
- package/dist/chunk-7LDU7F5P.js.map +0 -1
- package/dist/chunk-B22X3IEZ.js.map +0 -1
- package/dist/chunk-YFQ7SGE4.js.map +0 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- Catalog endpoints are public data. Remove opaque query/fragment/userinfo/path URLs
|
|
3
|
+
-- imported before the catalog hygiene gate and prevent their continued use.
|
|
4
|
+
DELETE FROM "capability_installations" AS "installation"
|
|
5
|
+
WHERE EXISTS (
|
|
6
|
+
SELECT 1
|
|
7
|
+
FROM "capability_catalog_items" AS "registry_item"
|
|
8
|
+
WHERE
|
|
9
|
+
"registry_item"."id" = "installation"."capability_id"
|
|
10
|
+
AND "registry_item"."workspace_id" IS NULL
|
|
11
|
+
AND "registry_item"."source" = 'registry'
|
|
12
|
+
AND "registry_item"."metadata" ->> 'registry' = 'integrations.sh'
|
|
13
|
+
AND (
|
|
14
|
+
"registry_item"."endpoint_url" LIKE '%?%'
|
|
15
|
+
OR "registry_item"."endpoint_url" LIKE '%#%'
|
|
16
|
+
OR "registry_item"."endpoint_url" ~* '^https?://[^/?#]*@'
|
|
17
|
+
OR "registry_item"."endpoint_url" ~* '^https?://[^/?#]+/(?:[^/?#]*/)*[^/?#]{24,}(?:/|$)'
|
|
18
|
+
OR "registry_item"."mcp_url" LIKE '%?%'
|
|
19
|
+
OR "registry_item"."mcp_url" LIKE '%#%'
|
|
20
|
+
OR "registry_item"."mcp_url" ~* '^https?://[^/?#]*@'
|
|
21
|
+
OR "registry_item"."mcp_url" ~* '^https?://[^/?#]+/(?:[^/?#]*/)*[^/?#]{24,}(?:/|$)'
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
AND NOT EXISTS (
|
|
25
|
+
SELECT 1
|
|
26
|
+
FROM "capability_catalog_items" AS "workspace_item"
|
|
27
|
+
WHERE
|
|
28
|
+
"workspace_item"."workspace_id" = "installation"."workspace_id"
|
|
29
|
+
AND "workspace_item"."id" = "installation"."capability_id"
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
DELETE FROM "capability_catalog_items"
|
|
33
|
+
WHERE
|
|
34
|
+
"source" = 'registry'
|
|
35
|
+
AND "metadata" ->> 'registry' = 'integrations.sh'
|
|
36
|
+
AND (
|
|
37
|
+
"endpoint_url" LIKE '%?%'
|
|
38
|
+
OR "endpoint_url" LIKE '%#%'
|
|
39
|
+
OR "endpoint_url" ~* '^https?://[^/?#]*@'
|
|
40
|
+
OR "endpoint_url" ~* '^https?://[^/?#]+/(?:[^/?#]*/)*[^/?#]{24,}(?:/|$)'
|
|
41
|
+
OR "mcp_url" LIKE '%?%'
|
|
42
|
+
OR "mcp_url" LIKE '%#%'
|
|
43
|
+
OR "mcp_url" ~* '^https?://[^/?#]*@'
|
|
44
|
+
OR "mcp_url" ~* '^https?://[^/?#]+/(?:[^/?#]*/)*[^/?#]{24,}(?:/|$)'
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
-- Earlier import diagnostics may contain the same URLs. Counts remain in their
|
|
48
|
+
-- dedicated columns; the unstructured diagnostic payload is not authoritative.
|
|
49
|
+
UPDATE "import_batches"
|
|
50
|
+
SET "details" = '{}'::jsonb, "updated_at" = NOW()
|
|
51
|
+
WHERE "source" = 'integrations.sh';
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
|
|
3
|
+
ALTER TABLE "github_installations"
|
|
4
|
+
ADD COLUMN IF NOT EXISTS "repository_scope" text NOT NULL DEFAULT 'all';
|
|
5
|
+
ALTER TABLE "github_installations"
|
|
6
|
+
ADD COLUMN IF NOT EXISTS "linked_by_subject_id" text;
|
|
7
|
+
|
|
8
|
+
DO $$
|
|
9
|
+
BEGIN
|
|
10
|
+
IF NOT EXISTS (
|
|
11
|
+
SELECT 1 FROM pg_constraint
|
|
12
|
+
WHERE conname = 'github_installations_repository_scope_check'
|
|
13
|
+
AND conrelid = 'github_installations'::regclass
|
|
14
|
+
) THEN
|
|
15
|
+
ALTER TABLE "github_installations"
|
|
16
|
+
ADD CONSTRAINT "github_installations_repository_scope_check"
|
|
17
|
+
CHECK ("repository_scope" IN ('all', 'selected'));
|
|
18
|
+
END IF;
|
|
19
|
+
END $$;
|
|
20
|
+
|
|
21
|
+
CREATE TABLE IF NOT EXISTS "github_installation_repositories" (
|
|
22
|
+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
23
|
+
"account_id" uuid NOT NULL REFERENCES "managed_accounts"("id") ON DELETE CASCADE,
|
|
24
|
+
"workspace_id" uuid NOT NULL REFERENCES "workspaces"("id") ON DELETE CASCADE,
|
|
25
|
+
"installation_id" integer NOT NULL,
|
|
26
|
+
"repository_id" bigint NOT NULL,
|
|
27
|
+
"created_at" timestamptz NOT NULL DEFAULT now()
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
DO $$
|
|
31
|
+
BEGIN
|
|
32
|
+
IF NOT EXISTS (
|
|
33
|
+
SELECT 1 FROM pg_constraint
|
|
34
|
+
WHERE conname = 'github_installation_repositories_workspace_account_fk'
|
|
35
|
+
AND conrelid = 'github_installation_repositories'::regclass
|
|
36
|
+
) THEN
|
|
37
|
+
ALTER TABLE "github_installation_repositories"
|
|
38
|
+
ADD CONSTRAINT "github_installation_repositories_workspace_account_fk"
|
|
39
|
+
FOREIGN KEY ("workspace_id", "account_id")
|
|
40
|
+
REFERENCES "workspaces"("id", "account_id") ON DELETE CASCADE;
|
|
41
|
+
END IF;
|
|
42
|
+
IF NOT EXISTS (
|
|
43
|
+
SELECT 1 FROM pg_constraint
|
|
44
|
+
WHERE conname = 'github_installation_repositories_installation_fk'
|
|
45
|
+
AND conrelid = 'github_installation_repositories'::regclass
|
|
46
|
+
) THEN
|
|
47
|
+
ALTER TABLE "github_installation_repositories"
|
|
48
|
+
ADD CONSTRAINT "github_installation_repositories_installation_fk"
|
|
49
|
+
FOREIGN KEY ("workspace_id", "installation_id")
|
|
50
|
+
REFERENCES "github_installations"("workspace_id", "installation_id") ON DELETE CASCADE;
|
|
51
|
+
END IF;
|
|
52
|
+
END $$;
|
|
53
|
+
|
|
54
|
+
CREATE UNIQUE INDEX IF NOT EXISTS "github_install_repo_workspace_installation_repo_idx"
|
|
55
|
+
ON "github_installation_repositories" ("workspace_id", "installation_id", "repository_id");
|
|
56
|
+
CREATE INDEX IF NOT EXISTS "github_install_repo_workspace_installation_idx"
|
|
57
|
+
ON "github_installation_repositories" ("workspace_id", "installation_id");
|
|
58
|
+
|
|
59
|
+
ALTER TABLE "github_installation_repositories" ENABLE ROW LEVEL SECURITY;
|
|
60
|
+
ALTER TABLE "github_installation_repositories" FORCE ROW LEVEL SECURITY;
|
|
61
|
+
DO $$
|
|
62
|
+
BEGIN
|
|
63
|
+
IF EXISTS (
|
|
64
|
+
SELECT 1 FROM pg_policies
|
|
65
|
+
WHERE schemaname = current_schema()
|
|
66
|
+
AND tablename = 'github_installation_repositories'
|
|
67
|
+
AND policyname = 'workspace_isolation'
|
|
68
|
+
) THEN
|
|
69
|
+
DROP POLICY workspace_isolation ON "github_installation_repositories";
|
|
70
|
+
END IF;
|
|
71
|
+
END $$;
|
|
72
|
+
CREATE POLICY workspace_isolation ON "github_installation_repositories"
|
|
73
|
+
USING (opengeni_private.workspace_rls_visible(account_id, workspace_id))
|
|
74
|
+
WITH CHECK (opengeni_private.workspace_rls_visible(account_id, workspace_id));
|
|
75
|
+
|
|
76
|
+
DO $$
|
|
77
|
+
BEGIN
|
|
78
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'opengeni_app') THEN
|
|
79
|
+
EXECUTE format(
|
|
80
|
+
'GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA %I TO opengeni_app',
|
|
81
|
+
current_schema()
|
|
82
|
+
);
|
|
83
|
+
END IF;
|
|
84
|
+
END $$;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- Existing rows and old rolling-deploy writers receive an explicit service
|
|
3
|
+
-- sentinel. Host credential resolvers must reject that sentinel; it is never
|
|
4
|
+
-- inferred back to a session creator.
|
|
5
|
+
|
|
6
|
+
ALTER TABLE "sessions"
|
|
7
|
+
ADD COLUMN IF NOT EXISTS "created_by_kind" text NOT NULL DEFAULT 'service',
|
|
8
|
+
ADD COLUMN IF NOT EXISTS "created_by_subject_id" text NOT NULL DEFAULT 'unattributed-legacy',
|
|
9
|
+
ADD COLUMN IF NOT EXISTS "created_by_context" jsonb NOT NULL DEFAULT '{"backfill":true}'::jsonb;
|
|
10
|
+
|
|
11
|
+
ALTER TABLE "session_turns"
|
|
12
|
+
ADD COLUMN IF NOT EXISTS "initiator_kind" text NOT NULL DEFAULT 'service',
|
|
13
|
+
ADD COLUMN IF NOT EXISTS "initiator_subject_id" text NOT NULL DEFAULT 'unattributed-legacy',
|
|
14
|
+
ADD COLUMN IF NOT EXISTS "initiator_context" jsonb NOT NULL DEFAULT '{"backfill":true}'::jsonb;
|
|
15
|
+
|
|
16
|
+
DO $$
|
|
17
|
+
BEGIN
|
|
18
|
+
IF NOT EXISTS (
|
|
19
|
+
SELECT 1 FROM pg_constraint
|
|
20
|
+
WHERE conname = 'sessions_created_by_kind_check'
|
|
21
|
+
AND conrelid = 'sessions'::regclass
|
|
22
|
+
) THEN
|
|
23
|
+
ALTER TABLE "sessions"
|
|
24
|
+
ADD CONSTRAINT "sessions_created_by_kind_check"
|
|
25
|
+
CHECK ("created_by_kind" IN ('subject', 'service')) NOT VALID;
|
|
26
|
+
END IF;
|
|
27
|
+
IF NOT EXISTS (
|
|
28
|
+
SELECT 1 FROM pg_constraint
|
|
29
|
+
WHERE conname = 'session_turns_initiator_kind_check'
|
|
30
|
+
AND conrelid = 'session_turns'::regclass
|
|
31
|
+
) THEN
|
|
32
|
+
ALTER TABLE "session_turns"
|
|
33
|
+
ADD CONSTRAINT "session_turns_initiator_kind_check"
|
|
34
|
+
CHECK ("initiator_kind" IN ('subject', 'service')) NOT VALID;
|
|
35
|
+
END IF;
|
|
36
|
+
END $$;
|
|
37
|
+
|
|
38
|
+
ALTER TABLE "sessions" VALIDATE CONSTRAINT "sessions_created_by_kind_check";
|
|
39
|
+
ALTER TABLE "session_turns" VALIDATE CONSTRAINT "session_turns_initiator_kind_check";
|
|
40
|
+
|
|
41
|
+
CREATE OR REPLACE FUNCTION opengeni_private.prevent_session_creator_mutation()
|
|
42
|
+
RETURNS trigger
|
|
43
|
+
LANGUAGE plpgsql
|
|
44
|
+
AS $$
|
|
45
|
+
BEGIN
|
|
46
|
+
IF NEW.created_by_kind IS DISTINCT FROM OLD.created_by_kind
|
|
47
|
+
OR NEW.created_by_subject_id IS DISTINCT FROM OLD.created_by_subject_id
|
|
48
|
+
OR NEW.created_by_context IS DISTINCT FROM OLD.created_by_context
|
|
49
|
+
THEN
|
|
50
|
+
RAISE EXCEPTION 'session creator is immutable' USING ERRCODE = '23514';
|
|
51
|
+
END IF;
|
|
52
|
+
RETURN NEW;
|
|
53
|
+
END;
|
|
54
|
+
$$;
|
|
55
|
+
|
|
56
|
+
CREATE OR REPLACE FUNCTION opengeni_private.prevent_session_turn_initiator_mutation()
|
|
57
|
+
RETURNS trigger
|
|
58
|
+
LANGUAGE plpgsql
|
|
59
|
+
AS $$
|
|
60
|
+
BEGIN
|
|
61
|
+
IF NEW.initiator_kind IS DISTINCT FROM OLD.initiator_kind
|
|
62
|
+
OR NEW.initiator_subject_id IS DISTINCT FROM OLD.initiator_subject_id
|
|
63
|
+
OR NEW.initiator_context IS DISTINCT FROM OLD.initiator_context
|
|
64
|
+
THEN
|
|
65
|
+
RAISE EXCEPTION 'session turn initiator is immutable' USING ERRCODE = '23514';
|
|
66
|
+
END IF;
|
|
67
|
+
RETURN NEW;
|
|
68
|
+
END;
|
|
69
|
+
$$;
|
|
70
|
+
|
|
71
|
+
DO $$
|
|
72
|
+
BEGIN
|
|
73
|
+
IF NOT EXISTS (
|
|
74
|
+
SELECT 1 FROM pg_trigger
|
|
75
|
+
WHERE tgname = 'sessions_creator_immutable'
|
|
76
|
+
AND tgrelid = 'sessions'::regclass
|
|
77
|
+
AND NOT tgisinternal
|
|
78
|
+
) THEN
|
|
79
|
+
CREATE TRIGGER sessions_creator_immutable
|
|
80
|
+
BEFORE UPDATE OF created_by_kind, created_by_subject_id, created_by_context
|
|
81
|
+
ON "sessions"
|
|
82
|
+
FOR EACH ROW
|
|
83
|
+
EXECUTE FUNCTION opengeni_private.prevent_session_creator_mutation();
|
|
84
|
+
END IF;
|
|
85
|
+
IF NOT EXISTS (
|
|
86
|
+
SELECT 1 FROM pg_trigger
|
|
87
|
+
WHERE tgname = 'session_turns_initiator_immutable'
|
|
88
|
+
AND tgrelid = 'session_turns'::regclass
|
|
89
|
+
AND NOT tgisinternal
|
|
90
|
+
) THEN
|
|
91
|
+
CREATE TRIGGER session_turns_initiator_immutable
|
|
92
|
+
BEFORE UPDATE OF initiator_kind, initiator_subject_id, initiator_context
|
|
93
|
+
ON "session_turns"
|
|
94
|
+
FOR EACH ROW
|
|
95
|
+
EXECUTE FUNCTION opengeni_private.prevent_session_turn_initiator_mutation();
|
|
96
|
+
END IF;
|
|
97
|
+
END $$;
|