@sixb/sqlite 0.1.6 → 0.1.8
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/agents/rows.d.ts +7 -4
- package/dist/agents/rows.d.ts.map +1 -1
- package/dist/agents/runs.d.ts +3 -2
- package/dist/agents/runs.d.ts.map +1 -1
- package/dist/agents/threads.d.ts.map +1 -1
- package/dist/ai-cost-groups.d.ts +5 -0
- package/dist/ai-cost-groups.d.ts.map +1 -0
- package/dist/ai-cost-storage.d.ts +2 -1
- package/dist/ai-cost-storage.d.ts.map +1 -1
- package/dist/ai-limit-storage.d.ts +35 -0
- package/dist/ai-limit-storage.d.ts.map +1 -0
- package/dist/ai-usage-storage.d.ts +1 -0
- package/dist/ai-usage-storage.d.ts.map +1 -1
- package/dist/auth-storage/access-tokens.d.ts +1 -1
- package/dist/auth-storage/access-tokens.d.ts.map +1 -1
- package/dist/auth-storage/auth-storage.d.ts +4 -1
- package/dist/auth-storage/auth-storage.d.ts.map +1 -1
- package/dist/auth-storage/device-authorizations.d.ts +29 -0
- package/dist/auth-storage/device-authorizations.d.ts.map +1 -0
- package/dist/auth-storage/rows.d.ts +19 -1
- package/dist/auth-storage/rows.d.ts.map +1 -1
- package/dist/auth-storage/shared.d.ts +1 -1
- package/dist/auth-storage/shared.d.ts.map +1 -1
- package/dist/execution-storage.d.ts +3 -2
- package/dist/execution-storage.d.ts.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3443 -789
- package/dist/index.js.map +29 -20
- package/dist/migrations.d.ts.map +1 -1
- package/dist/objects/index.d.ts +3 -0
- package/dist/objects/index.d.ts.map +1 -0
- package/dist/{object-query-compiler.d.ts → objects/query-compiler.d.ts} +16 -1
- package/dist/objects/query-compiler.d.ts.map +1 -0
- package/dist/objects/read-scope.d.ts +17 -0
- package/dist/objects/read-scope.d.ts.map +1 -0
- package/dist/objects/reader.d.ts +51 -0
- package/dist/objects/reader.d.ts.map +1 -0
- package/dist/objects/rows.d.ts +33 -0
- package/dist/objects/rows.d.ts.map +1 -0
- package/dist/objects/selected-reader.d.ts +9 -0
- package/dist/objects/selected-reader.d.ts.map +1 -0
- package/dist/{object-storage.d.ts → objects/storage.d.ts} +12 -9
- package/dist/objects/storage.d.ts.map +1 -0
- package/dist/share-grant-storage.d.ts +20 -0
- package/dist/share-grant-storage.d.ts.map +1 -0
- package/dist/share-session-storage.d.ts +19 -0
- package/dist/share-session-storage.d.ts.map +1 -0
- package/dist/storage-errors.d.ts +1 -0
- package/dist/storage-errors.d.ts.map +1 -1
- package/dist/transactions.d.ts +8 -0
- package/dist/transactions.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/agents/rows.ts +36 -9
- package/src/agents/runs.ts +152 -13
- package/src/agents/threads.ts +2 -17
- package/src/ai-cost-groups.ts +100 -0
- package/src/ai-cost-storage.ts +67 -25
- package/src/ai-limit-storage.ts +981 -0
- package/src/ai-usage-storage.ts +24 -1
- package/src/auth-storage/access-tokens.ts +77 -68
- package/src/auth-storage/auth-storage.ts +80 -1
- package/src/auth-storage/device-authorizations.ts +153 -0
- package/src/auth-storage/rows.ts +41 -0
- package/src/auth-storage/shared.ts +1 -0
- package/src/execution-storage.ts +22 -3
- package/src/index.ts +24 -3
- package/src/migrations/029-model-accounting.sql +79 -0
- package/src/migrations/030-ai-usage-limits.sql +100 -0
- package/src/migrations/031-subagent-runs.sql +231 -0
- package/src/migrations/032-conversation-run-spec.sql +78 -0
- package/src/migrations/033-retire-agent-definitions.sql +89 -0
- package/src/migrations/034-device-authorizations.sql +22 -0
- package/src/migrations/035-share-grants.sql +66 -0
- package/src/migrations/036-share-sessions.sql +226 -0
- package/src/migrations.ts +22 -0
- package/src/objects/index.ts +2 -0
- package/src/{object-query-compiler.ts → objects/query-compiler.ts} +104 -54
- package/src/objects/read-scope.ts +316 -0
- package/src/objects/reader.ts +526 -0
- package/src/objects/rows.ts +123 -0
- package/src/objects/selected-reader.ts +119 -0
- package/src/objects/storage.ts +296 -0
- package/src/share-grant-storage.ts +252 -0
- package/src/share-session-storage.ts +189 -0
- package/src/storage-errors.ts +4 -0
- package/src/transactions.ts +32 -0
- package/src/workflow-run-storage.ts +8 -8
- package/dist/object-query-compiler.d.ts.map +0 -1
- package/dist/object-storage.d.ts.map +0 -1
- package/src/object-storage.ts +0 -709
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
DROP INDEX idx_agent_threads_project_agent_activity;
|
|
2
|
+
ALTER TABLE workflow_agent_node_runs RENAME COLUMN agent_id TO actor_id;
|
|
3
|
+
ALTER TABLE agent_threads DROP COLUMN agent_id;
|
|
4
|
+
|
|
5
|
+
CREATE TABLE agent_runs_v5 (
|
|
6
|
+
project_id TEXT NOT NULL,
|
|
7
|
+
id TEXT NOT NULL,
|
|
8
|
+
execution_id TEXT NOT NULL,
|
|
9
|
+
kind TEXT NOT NULL DEFAULT 'conversation' CHECK (kind IN ('conversation', 'subagent')),
|
|
10
|
+
thread_id TEXT,
|
|
11
|
+
trigger_message_id TEXT,
|
|
12
|
+
parent_run_id TEXT,
|
|
13
|
+
spawn_key TEXT,
|
|
14
|
+
spec TEXT CHECK (spec IS NULL OR json_valid(spec)),
|
|
15
|
+
result TEXT CHECK (result IS NULL OR json_valid(result)),
|
|
16
|
+
requester_group_ids TEXT NOT NULL DEFAULT '[]'
|
|
17
|
+
CHECK (json_valid(requester_group_ids) AND json_type(requester_group_ids) = 'array'),
|
|
18
|
+
status TEXT NOT NULL CHECK (
|
|
19
|
+
status IN ('queued', 'running', 'succeeded', 'failed', 'cancelled')
|
|
20
|
+
),
|
|
21
|
+
model_id TEXT,
|
|
22
|
+
finish_reason TEXT,
|
|
23
|
+
error TEXT CHECK (error IS NULL OR json_valid(error)),
|
|
24
|
+
diagnostics TEXT,
|
|
25
|
+
attempt INTEGER NOT NULL DEFAULT 0 CHECK (attempt >= 0),
|
|
26
|
+
execution_token TEXT,
|
|
27
|
+
execution_queue_lease_expires_at TEXT,
|
|
28
|
+
created_at TEXT NOT NULL,
|
|
29
|
+
started_at TEXT,
|
|
30
|
+
completed_at TEXT,
|
|
31
|
+
PRIMARY KEY (project_id, id),
|
|
32
|
+
UNIQUE (project_id, execution_id),
|
|
33
|
+
UNIQUE (project_id, parent_run_id, spawn_key),
|
|
34
|
+
FOREIGN KEY (project_id, execution_id)
|
|
35
|
+
REFERENCES executions (project_id, id)
|
|
36
|
+
ON DELETE RESTRICT,
|
|
37
|
+
FOREIGN KEY (project_id, parent_run_id)
|
|
38
|
+
-- Use the final name: Bun's legacy ALTER mode preserves references when foreign keys are off.
|
|
39
|
+
REFERENCES agent_runs (project_id, id)
|
|
40
|
+
ON DELETE RESTRICT,
|
|
41
|
+
CHECK ((execution_token IS NULL) = (execution_queue_lease_expires_at IS NULL)),
|
|
42
|
+
CHECK (
|
|
43
|
+
(
|
|
44
|
+
kind = 'conversation'
|
|
45
|
+
AND thread_id IS NOT NULL
|
|
46
|
+
AND trigger_message_id IS NOT NULL
|
|
47
|
+
AND parent_run_id IS NULL
|
|
48
|
+
AND spawn_key IS NULL
|
|
49
|
+
AND result IS NULL
|
|
50
|
+
)
|
|
51
|
+
OR
|
|
52
|
+
(
|
|
53
|
+
kind = 'subagent'
|
|
54
|
+
AND thread_id IS NULL
|
|
55
|
+
AND trigger_message_id IS NULL
|
|
56
|
+
AND parent_run_id IS NOT NULL
|
|
57
|
+
AND spawn_key IS NOT NULL
|
|
58
|
+
AND spec IS NOT NULL
|
|
59
|
+
)
|
|
60
|
+
),
|
|
61
|
+
CHECK (kind <> 'subagent' OR status <> 'succeeded' OR result IS NOT NULL)
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
INSERT INTO agent_runs_v5 (
|
|
65
|
+
project_id, id, execution_id, kind, thread_id, trigger_message_id, parent_run_id, spawn_key,
|
|
66
|
+
spec, result, requester_group_ids, status, model_id, finish_reason, error, diagnostics, attempt,
|
|
67
|
+
execution_token, execution_queue_lease_expires_at, created_at, started_at, completed_at
|
|
68
|
+
)
|
|
69
|
+
SELECT
|
|
70
|
+
project_id, id, execution_id, kind, thread_id, trigger_message_id, parent_run_id, spawn_key,
|
|
71
|
+
spec, result, requester_group_ids, status, model_id, finish_reason, error, diagnostics, attempt,
|
|
72
|
+
execution_token, execution_queue_lease_expires_at, created_at, started_at, completed_at
|
|
73
|
+
FROM agent_runs;
|
|
74
|
+
|
|
75
|
+
DROP TABLE agent_runs;
|
|
76
|
+
ALTER TABLE agent_runs_v5 RENAME TO agent_runs;
|
|
77
|
+
|
|
78
|
+
CREATE INDEX idx_agent_runs_project_thread_started
|
|
79
|
+
ON agent_runs (project_id, thread_id, COALESCE(started_at, created_at) DESC, id DESC);
|
|
80
|
+
CREATE INDEX idx_agent_runs_project_status_created
|
|
81
|
+
ON agent_runs (project_id, status, created_at, id);
|
|
82
|
+
CREATE INDEX idx_agent_runs_project_parent_started
|
|
83
|
+
ON agent_runs (
|
|
84
|
+
project_id,
|
|
85
|
+
parent_run_id,
|
|
86
|
+
status,
|
|
87
|
+
COALESCE(started_at, created_at) DESC,
|
|
88
|
+
id DESC
|
|
89
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
CREATE TABLE auth_device_authorizations (
|
|
2
|
+
project_id TEXT NOT NULL,
|
|
3
|
+
id TEXT NOT NULL,
|
|
4
|
+
device_code_hash TEXT NOT NULL,
|
|
5
|
+
user_code TEXT NOT NULL,
|
|
6
|
+
client_name TEXT NOT NULL,
|
|
7
|
+
token_name TEXT NOT NULL,
|
|
8
|
+
token_expires_at TEXT NOT NULL,
|
|
9
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'approved', 'denied', 'consumed')),
|
|
10
|
+
approved_user_id TEXT,
|
|
11
|
+
approved_session_id TEXT,
|
|
12
|
+
created_at TEXT NOT NULL,
|
|
13
|
+
expires_at TEXT NOT NULL,
|
|
14
|
+
approved_at TEXT,
|
|
15
|
+
denied_at TEXT,
|
|
16
|
+
consumed_at TEXT,
|
|
17
|
+
PRIMARY KEY (project_id, id),
|
|
18
|
+
UNIQUE (project_id, user_code)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
CREATE INDEX idx_auth_device_authorizations_pending
|
|
22
|
+
ON auth_device_authorizations(project_id, status, expires_at);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
CREATE TABLE share_grants (
|
|
2
|
+
project_id TEXT NOT NULL CHECK (length(trim(project_id)) > 0),
|
|
3
|
+
id TEXT NOT NULL CHECK (length(trim(id)) > 0),
|
|
4
|
+
definition_id TEXT NOT NULL CHECK (length(trim(definition_id)) > 0),
|
|
5
|
+
target_object_type_id TEXT NOT NULL CHECK (length(trim(target_object_type_id)) > 0),
|
|
6
|
+
target_primary_id TEXT NOT NULL CHECK (length(trim(target_primary_id)) > 0),
|
|
7
|
+
issued_by_type TEXT NOT NULL CHECK (issued_by_type IN ('user', 'serviceAccount')),
|
|
8
|
+
issued_by_id TEXT NOT NULL CHECK (length(trim(issued_by_id)) > 0),
|
|
9
|
+
authority_version INTEGER NOT NULL CHECK (authority_version > 0),
|
|
10
|
+
authority_snapshot TEXT NOT NULL CHECK (
|
|
11
|
+
json_valid(authority_snapshot)
|
|
12
|
+
AND json_type(authority_snapshot) = 'object'
|
|
13
|
+
AND json_type(authority_snapshot, '$.version') = 'integer'
|
|
14
|
+
AND json_extract(authority_snapshot, '$.version') = authority_version
|
|
15
|
+
AND json_type(authority_snapshot, '$.access') = 'object'
|
|
16
|
+
),
|
|
17
|
+
authority_digest TEXT NOT NULL CHECK (
|
|
18
|
+
length(authority_digest) = 64
|
|
19
|
+
AND authority_digest = lower(authority_digest)
|
|
20
|
+
AND authority_digest NOT GLOB '*[^0-9a-f]*'
|
|
21
|
+
),
|
|
22
|
+
token_hash TEXT NOT NULL CHECK (
|
|
23
|
+
length(token_hash) = 64
|
|
24
|
+
AND token_hash = lower(token_hash)
|
|
25
|
+
AND token_hash NOT GLOB '*[^0-9a-f]*'
|
|
26
|
+
),
|
|
27
|
+
destination_path TEXT NOT NULL CHECK (
|
|
28
|
+
substr(destination_path, 1, 1) = '/'
|
|
29
|
+
AND instr(destination_path, '?') = 0
|
|
30
|
+
AND instr(destination_path, '#') = 0
|
|
31
|
+
AND instr(destination_path, char(92)) = 0
|
|
32
|
+
),
|
|
33
|
+
created_at TEXT NOT NULL,
|
|
34
|
+
expires_at TEXT NOT NULL,
|
|
35
|
+
revoked_at TEXT,
|
|
36
|
+
revoked_by_type TEXT CHECK (
|
|
37
|
+
revoked_by_type IS NULL OR revoked_by_type IN ('user', 'serviceAccount', 'system')
|
|
38
|
+
),
|
|
39
|
+
revoked_by_id TEXT CHECK (revoked_by_id IS NULL OR length(trim(revoked_by_id)) > 0),
|
|
40
|
+
PRIMARY KEY (project_id, id),
|
|
41
|
+
UNIQUE (project_id, token_hash),
|
|
42
|
+
CHECK (expires_at > created_at),
|
|
43
|
+
CHECK (revoked_at IS NULL OR revoked_at >= created_at),
|
|
44
|
+
CHECK (
|
|
45
|
+
(revoked_at IS NULL AND revoked_by_type IS NULL AND revoked_by_id IS NULL)
|
|
46
|
+
OR
|
|
47
|
+
(revoked_at IS NOT NULL AND revoked_by_type IS NOT NULL AND revoked_by_id IS NOT NULL)
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
CREATE INDEX idx_share_grants_target
|
|
52
|
+
ON share_grants (
|
|
53
|
+
project_id,
|
|
54
|
+
definition_id,
|
|
55
|
+
target_object_type_id,
|
|
56
|
+
target_primary_id,
|
|
57
|
+
created_at DESC,
|
|
58
|
+
id DESC
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
CREATE INDEX idx_share_grants_project_created
|
|
62
|
+
ON share_grants (project_id, created_at DESC, id DESC);
|
|
63
|
+
|
|
64
|
+
CREATE INDEX idx_share_grants_expiry
|
|
65
|
+
ON share_grants (project_id, expires_at)
|
|
66
|
+
WHERE revoked_at IS NULL;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
-- Shared sessions and their execution provenance.
|
|
2
|
+
CREATE TABLE share_sessions (
|
|
3
|
+
project_id TEXT NOT NULL CHECK (length(trim(project_id)) > 0),
|
|
4
|
+
id TEXT NOT NULL CHECK (length(trim(id)) > 0),
|
|
5
|
+
grant_id TEXT NOT NULL CHECK (length(trim(grant_id)) > 0),
|
|
6
|
+
token_hash TEXT NOT NULL CHECK (
|
|
7
|
+
length(token_hash) = 64
|
|
8
|
+
AND token_hash = lower(token_hash)
|
|
9
|
+
AND token_hash NOT GLOB '*[^0-9a-f]*'
|
|
10
|
+
),
|
|
11
|
+
created_at TEXT NOT NULL,
|
|
12
|
+
expires_at TEXT NOT NULL,
|
|
13
|
+
absolute_expires_at TEXT NOT NULL,
|
|
14
|
+
revoked_at TEXT,
|
|
15
|
+
PRIMARY KEY (project_id, id),
|
|
16
|
+
UNIQUE (project_id, id, grant_id),
|
|
17
|
+
UNIQUE (project_id, token_hash),
|
|
18
|
+
FOREIGN KEY (project_id, grant_id)
|
|
19
|
+
REFERENCES share_grants (project_id, id),
|
|
20
|
+
CHECK (expires_at > created_at),
|
|
21
|
+
CHECK (absolute_expires_at > created_at),
|
|
22
|
+
CHECK (expires_at <= absolute_expires_at),
|
|
23
|
+
CHECK (revoked_at IS NULL OR revoked_at >= created_at)
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
CREATE INDEX idx_share_sessions_grant
|
|
27
|
+
ON share_sessions (project_id, grant_id, created_at DESC, id DESC);
|
|
28
|
+
|
|
29
|
+
CREATE INDEX idx_share_sessions_expiry
|
|
30
|
+
ON share_sessions (project_id, expires_at)
|
|
31
|
+
WHERE revoked_at IS NULL;
|
|
32
|
+
|
|
33
|
+
-- Persist shared-session provenance on request executions without fabricating a principal.
|
|
34
|
+
CREATE TABLE executions_v2 (
|
|
35
|
+
project_id TEXT NOT NULL CHECK (length(trim(project_id)) > 0),
|
|
36
|
+
id TEXT NOT NULL CHECK (length(trim(id)) > 0),
|
|
37
|
+
executor_kind TEXT NOT NULL CHECK (
|
|
38
|
+
executor_kind IN (
|
|
39
|
+
'request', 'action', 'pipeline', 'projection', 'rule', 'sync', 'webhook', 'workflow',
|
|
40
|
+
'agent', 'kernel'
|
|
41
|
+
)
|
|
42
|
+
),
|
|
43
|
+
executor_id TEXT NOT NULL CHECK (length(trim(executor_id)) > 0),
|
|
44
|
+
source_kind TEXT NOT NULL CHECK (
|
|
45
|
+
source_kind IN ('http', 'webhook', 'schedule', 'event', 'datasetVersion', 'execution')
|
|
46
|
+
),
|
|
47
|
+
source_id TEXT NOT NULL CHECK (length(trim(source_id)) > 0),
|
|
48
|
+
requested_by_user_id TEXT,
|
|
49
|
+
requested_by_service_account_id TEXT,
|
|
50
|
+
correlation_id TEXT NOT NULL CHECK (length(trim(correlation_id)) > 0),
|
|
51
|
+
parent_execution_id TEXT,
|
|
52
|
+
authority_kind TEXT NOT NULL CHECK (
|
|
53
|
+
authority_kind IN ('principal', 'trustedPrimitive', 'delegated', 'kernel', 'disabled')
|
|
54
|
+
),
|
|
55
|
+
authority_user_id TEXT,
|
|
56
|
+
authority_service_account_id TEXT,
|
|
57
|
+
authority_session_id TEXT,
|
|
58
|
+
authority_access_token_id TEXT,
|
|
59
|
+
authority_primitive_kind TEXT CHECK (
|
|
60
|
+
authority_primitive_kind IS NULL
|
|
61
|
+
OR authority_primitive_kind IN (
|
|
62
|
+
'action', 'pipeline', 'projection', 'rule', 'sync', 'webhook', 'workflow'
|
|
63
|
+
)
|
|
64
|
+
),
|
|
65
|
+
authority_primitive_id TEXT,
|
|
66
|
+
authority_kernel_operation TEXT CHECK (
|
|
67
|
+
authority_kernel_operation IS NULL OR authority_kernel_operation = 'ontology.recover'
|
|
68
|
+
),
|
|
69
|
+
authority_delegation_kind TEXT CHECK (
|
|
70
|
+
authority_delegation_kind IS NULL OR authority_delegation_kind = 'share'
|
|
71
|
+
),
|
|
72
|
+
authority_delegation_id TEXT,
|
|
73
|
+
authority_delegation_session_id TEXT,
|
|
74
|
+
created_at TEXT NOT NULL,
|
|
75
|
+
PRIMARY KEY (project_id, id),
|
|
76
|
+
FOREIGN KEY (project_id, parent_execution_id) REFERENCES executions (project_id, id),
|
|
77
|
+
FOREIGN KEY (project_id, requested_by_user_id) REFERENCES auth_users (project_id, id),
|
|
78
|
+
FOREIGN KEY (project_id, requested_by_service_account_id)
|
|
79
|
+
REFERENCES auth_service_accounts (project_id, id),
|
|
80
|
+
FOREIGN KEY (project_id, authority_user_id) REFERENCES auth_users (project_id, id),
|
|
81
|
+
FOREIGN KEY (project_id, authority_service_account_id)
|
|
82
|
+
REFERENCES auth_service_accounts (project_id, id),
|
|
83
|
+
FOREIGN KEY (project_id, authority_session_id) REFERENCES auth_sessions (project_id, id),
|
|
84
|
+
FOREIGN KEY (project_id, authority_access_token_id)
|
|
85
|
+
REFERENCES auth_access_tokens (project_id, id),
|
|
86
|
+
FOREIGN KEY (
|
|
87
|
+
project_id, authority_delegation_session_id, authority_delegation_id
|
|
88
|
+
) REFERENCES share_sessions (project_id, id, grant_id),
|
|
89
|
+
CHECK ((requested_by_user_id IS NOT NULL) + (requested_by_service_account_id IS NOT NULL) <= 1),
|
|
90
|
+
CHECK (
|
|
91
|
+
(source_kind = 'execution' AND parent_execution_id = source_id)
|
|
92
|
+
OR (source_kind <> 'execution' AND parent_execution_id IS NULL)
|
|
93
|
+
),
|
|
94
|
+
CHECK (
|
|
95
|
+
(
|
|
96
|
+
authority_kind = 'principal'
|
|
97
|
+
AND (authority_user_id IS NOT NULL) + (authority_service_account_id IS NOT NULL) = 1
|
|
98
|
+
AND (authority_session_id IS NOT NULL) + (authority_access_token_id IS NOT NULL) <= 1
|
|
99
|
+
AND (authority_session_id IS NULL OR authority_user_id IS NOT NULL)
|
|
100
|
+
AND authority_primitive_kind IS NULL
|
|
101
|
+
AND authority_primitive_id IS NULL
|
|
102
|
+
AND authority_kernel_operation IS NULL
|
|
103
|
+
AND authority_delegation_kind IS NULL
|
|
104
|
+
AND authority_delegation_id IS NULL
|
|
105
|
+
AND authority_delegation_session_id IS NULL
|
|
106
|
+
)
|
|
107
|
+
OR (
|
|
108
|
+
authority_kind = 'trustedPrimitive'
|
|
109
|
+
AND authority_user_id IS NULL
|
|
110
|
+
AND authority_service_account_id IS NULL
|
|
111
|
+
AND authority_session_id IS NULL
|
|
112
|
+
AND authority_access_token_id IS NULL
|
|
113
|
+
AND authority_primitive_kind IS NOT NULL
|
|
114
|
+
AND authority_primitive_id IS NOT NULL
|
|
115
|
+
AND length(trim(authority_primitive_id)) > 0
|
|
116
|
+
AND authority_kernel_operation IS NULL
|
|
117
|
+
AND authority_delegation_kind IS NULL
|
|
118
|
+
AND authority_delegation_id IS NULL
|
|
119
|
+
AND authority_delegation_session_id IS NULL
|
|
120
|
+
)
|
|
121
|
+
OR (
|
|
122
|
+
authority_kind = 'delegated'
|
|
123
|
+
AND authority_user_id IS NULL
|
|
124
|
+
AND authority_service_account_id IS NULL
|
|
125
|
+
AND authority_session_id IS NULL
|
|
126
|
+
AND authority_access_token_id IS NULL
|
|
127
|
+
AND authority_primitive_kind IS NULL
|
|
128
|
+
AND authority_primitive_id IS NULL
|
|
129
|
+
AND authority_kernel_operation IS NULL
|
|
130
|
+
AND authority_delegation_kind IS NOT NULL
|
|
131
|
+
AND authority_delegation_kind = 'share'
|
|
132
|
+
AND authority_delegation_id IS NOT NULL
|
|
133
|
+
AND length(trim(authority_delegation_id)) > 0
|
|
134
|
+
AND authority_delegation_session_id IS NOT NULL
|
|
135
|
+
AND length(trim(authority_delegation_session_id)) > 0
|
|
136
|
+
)
|
|
137
|
+
OR (
|
|
138
|
+
authority_kind = 'kernel'
|
|
139
|
+
AND authority_user_id IS NULL
|
|
140
|
+
AND authority_service_account_id IS NULL
|
|
141
|
+
AND authority_session_id IS NULL
|
|
142
|
+
AND authority_access_token_id IS NULL
|
|
143
|
+
AND authority_primitive_kind IS NULL
|
|
144
|
+
AND authority_primitive_id IS NULL
|
|
145
|
+
AND authority_kernel_operation IS NOT NULL
|
|
146
|
+
AND authority_delegation_kind IS NULL
|
|
147
|
+
AND authority_delegation_id IS NULL
|
|
148
|
+
AND authority_delegation_session_id IS NULL
|
|
149
|
+
)
|
|
150
|
+
OR (
|
|
151
|
+
authority_kind = 'disabled'
|
|
152
|
+
AND authority_user_id IS NULL
|
|
153
|
+
AND authority_service_account_id IS NULL
|
|
154
|
+
AND authority_session_id IS NULL
|
|
155
|
+
AND authority_access_token_id IS NULL
|
|
156
|
+
AND authority_primitive_kind IS NULL
|
|
157
|
+
AND authority_primitive_id IS NULL
|
|
158
|
+
AND authority_kernel_operation IS NULL
|
|
159
|
+
AND authority_delegation_kind IS NULL
|
|
160
|
+
AND authority_delegation_id IS NULL
|
|
161
|
+
AND authority_delegation_session_id IS NULL
|
|
162
|
+
)
|
|
163
|
+
),
|
|
164
|
+
CHECK (
|
|
165
|
+
(
|
|
166
|
+
executor_kind = 'request'
|
|
167
|
+
AND source_kind = 'http'
|
|
168
|
+
AND executor_id = source_id
|
|
169
|
+
AND (
|
|
170
|
+
(
|
|
171
|
+
authority_kind = 'principal'
|
|
172
|
+
AND requested_by_user_id IS authority_user_id
|
|
173
|
+
AND requested_by_service_account_id IS authority_service_account_id
|
|
174
|
+
)
|
|
175
|
+
OR (
|
|
176
|
+
authority_kind IN ('delegated', 'disabled')
|
|
177
|
+
AND requested_by_user_id IS NULL
|
|
178
|
+
AND requested_by_service_account_id IS NULL
|
|
179
|
+
)
|
|
180
|
+
)
|
|
181
|
+
)
|
|
182
|
+
OR (
|
|
183
|
+
executor_kind IN ('action', 'pipeline', 'projection', 'rule', 'sync', 'webhook', 'workflow')
|
|
184
|
+
AND authority_kind = 'trustedPrimitive'
|
|
185
|
+
AND executor_kind = authority_primitive_kind
|
|
186
|
+
)
|
|
187
|
+
OR (
|
|
188
|
+
executor_kind = 'agent'
|
|
189
|
+
AND source_kind = 'execution'
|
|
190
|
+
AND (
|
|
191
|
+
(
|
|
192
|
+
authority_kind = 'principal'
|
|
193
|
+
AND authority_service_account_id IS NOT NULL
|
|
194
|
+
AND authority_session_id IS NULL
|
|
195
|
+
AND authority_access_token_id IS NULL
|
|
196
|
+
)
|
|
197
|
+
OR (
|
|
198
|
+
authority_kind = 'principal'
|
|
199
|
+
AND authority_user_id IS NOT NULL
|
|
200
|
+
AND (authority_session_id IS NOT NULL) + (authority_access_token_id IS NOT NULL) = 1
|
|
201
|
+
)
|
|
202
|
+
OR authority_kind = 'disabled'
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
OR (executor_kind = 'kernel' AND authority_kind = 'kernel')
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
INSERT INTO executions_v2 (
|
|
210
|
+
project_id, id, executor_kind, executor_id, source_kind, source_id,
|
|
211
|
+
requested_by_user_id, requested_by_service_account_id, correlation_id, parent_execution_id,
|
|
212
|
+
authority_kind, authority_user_id, authority_service_account_id, authority_session_id,
|
|
213
|
+
authority_access_token_id, authority_primitive_kind, authority_primitive_id,
|
|
214
|
+
authority_kernel_operation, authority_delegation_kind, authority_delegation_id,
|
|
215
|
+
authority_delegation_session_id, created_at
|
|
216
|
+
)
|
|
217
|
+
SELECT
|
|
218
|
+
project_id, id, executor_kind, executor_id, source_kind, source_id,
|
|
219
|
+
requested_by_user_id, requested_by_service_account_id, correlation_id, parent_execution_id,
|
|
220
|
+
authority_kind, authority_user_id, authority_service_account_id, authority_session_id,
|
|
221
|
+
authority_access_token_id, authority_primitive_kind, authority_primitive_id,
|
|
222
|
+
authority_kernel_operation, NULL, NULL, NULL, created_at
|
|
223
|
+
FROM executions;
|
|
224
|
+
|
|
225
|
+
DROP TABLE executions;
|
|
226
|
+
ALTER TABLE executions_v2 RENAME TO executions;
|
package/src/migrations.ts
CHANGED
|
@@ -76,6 +76,20 @@ import agentContextCheckpointsSql from "./migrations/027-agent-context-checkpoin
|
|
|
76
76
|
import objectOverrideEditTimesSql from "./migrations/028-object-override-edit-times.sql" with {
|
|
77
77
|
type: "text",
|
|
78
78
|
}
|
|
79
|
+
import modelAccountingSql from "./migrations/029-model-accounting.sql" with { type: "text" }
|
|
80
|
+
import aiUsageLimitsSql from "./migrations/030-ai-usage-limits.sql" with { type: "text" }
|
|
81
|
+
import subagentRunsSql from "./migrations/031-subagent-runs.sql" with { type: "text" }
|
|
82
|
+
import conversationRunSpecSql from "./migrations/032-conversation-run-spec.sql" with {
|
|
83
|
+
type: "text",
|
|
84
|
+
}
|
|
85
|
+
import retireAgentDefinitionsSql from "./migrations/033-retire-agent-definitions.sql" with {
|
|
86
|
+
type: "text",
|
|
87
|
+
}
|
|
88
|
+
import deviceAuthorizationsSql from "./migrations/034-device-authorizations.sql" with {
|
|
89
|
+
type: "text",
|
|
90
|
+
}
|
|
91
|
+
import shareGrantsSql from "./migrations/035-share-grants.sql" with { type: "text" }
|
|
92
|
+
import shareSessionsSql from "./migrations/036-share-sessions.sql" with { type: "text" }
|
|
79
93
|
|
|
80
94
|
const MIGRATIONS_TABLE_SQL = `
|
|
81
95
|
CREATE TABLE IF NOT EXISTS sixb_migrations (
|
|
@@ -159,6 +173,14 @@ export const sqliteStorageMigrations = defineMigrations({
|
|
|
159
173
|
sqliteSql("026-ai-cost-accounting", aiCostAccountingSql),
|
|
160
174
|
sqliteSql("027-agent-context-checkpoints", agentContextCheckpointsSql),
|
|
161
175
|
sqliteSql("028-object-override-edit-times", objectOverrideEditTimesSql),
|
|
176
|
+
sqliteSql("029-model-accounting", modelAccountingSql),
|
|
177
|
+
sqliteSql("030-ai-usage-limits", aiUsageLimitsSql),
|
|
178
|
+
sqliteSql("031-subagent-runs", subagentRunsSql),
|
|
179
|
+
sqliteSql("032-conversation-run-spec", conversationRunSpecSql),
|
|
180
|
+
sqliteSql("033-retire-agent-definitions", retireAgentDefinitionsSql),
|
|
181
|
+
sqliteSql("034-device-authorizations", deviceAuthorizationsSql),
|
|
182
|
+
sqliteSql("035-share-grants", shareGrantsSql),
|
|
183
|
+
sqliteSql("036-share-sessions", shareSessionsSql),
|
|
162
184
|
],
|
|
163
185
|
})
|
|
164
186
|
|