@sixb/sqlite 0.1.20 → 0.1.22
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/action-run-storage.d.ts +4 -0
- package/dist/action-run-storage.d.ts.map +1 -1
- package/dist/activity-storage.d.ts +20 -0
- package/dist/activity-storage.d.ts.map +1 -0
- package/dist/agents/agent-storage.d.ts +8 -2
- package/dist/agents/agent-storage.d.ts.map +1 -1
- package/dist/agents/approvals.d.ts +51 -0
- package/dist/agents/approvals.d.ts.map +1 -0
- package/dist/agents/checkpoints.d.ts +1 -0
- package/dist/agents/checkpoints.d.ts.map +1 -1
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/memory.d.ts +21 -0
- package/dist/agents/memory.d.ts.map +1 -0
- package/dist/agents/messages.d.ts.map +1 -1
- package/dist/agents/rows.d.ts +15 -1
- package/dist/agents/rows.d.ts.map +1 -1
- package/dist/agents/runs.d.ts +14 -1
- package/dist/agents/runs.d.ts.map +1 -1
- package/dist/agents/settings.d.ts +29 -0
- package/dist/agents/settings.d.ts.map +1 -0
- package/dist/agents/threads.d.ts +16 -1
- package/dist/agents/threads.d.ts.map +1 -1
- package/dist/ai-cost-groups.d.ts.map +1 -1
- package/dist/ai-cost-storage.d.ts.map +1 -1
- package/dist/ai-usage-storage.d.ts +4 -1
- package/dist/ai-usage-storage.d.ts.map +1 -1
- package/dist/artifact-storage.d.ts +31 -0
- package/dist/artifact-storage.d.ts.map +1 -0
- package/dist/auth-storage/auth-storage.d.ts +3 -2
- package/dist/auth-storage/auth-storage.d.ts.map +1 -1
- package/dist/auth-storage/sessions.d.ts +2 -1
- package/dist/auth-storage/sessions.d.ts.map +1 -1
- package/dist/auth-storage/users.d.ts +7 -3
- package/dist/auth-storage/users.d.ts.map +1 -1
- package/dist/execution-storage.d.ts +3 -1
- package/dist/execution-storage.d.ts.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5216 -2517
- package/dist/index.js.map +39 -31
- package/dist/migrations.d.ts +0 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/objects/conditional-reader.d.ts +8 -0
- package/dist/objects/conditional-reader.d.ts.map +1 -0
- package/dist/objects/query-compiler.d.ts +26 -1
- package/dist/objects/query-compiler.d.ts.map +1 -1
- package/dist/objects/read-scope.d.ts +10 -1
- package/dist/objects/read-scope.d.ts.map +1 -1
- package/dist/objects/reader.d.ts +2 -0
- package/dist/objects/reader.d.ts.map +1 -1
- package/dist/objects/scoped-reader.d.ts +15 -0
- package/dist/objects/scoped-reader.d.ts.map +1 -0
- package/dist/objects/selected-reader.d.ts.map +1 -1
- package/dist/objects/storage.d.ts +6 -1
- package/dist/objects/storage.d.ts.map +1 -1
- package/dist/ontology-storage/index.d.ts +2 -0
- package/dist/ontology-storage/index.d.ts.map +1 -1
- package/dist/ontology-storage/materialization-writer.d.ts +2 -0
- package/dist/ontology-storage/materialization-writer.d.ts.map +1 -1
- package/dist/ontology-storage/materializations.d.ts.map +1 -1
- package/dist/ontology-storage/sources.d.ts +2 -1
- package/dist/ontology-storage/sources.d.ts.map +1 -1
- package/dist/ontology-storage/unique-values.d.ts +42 -0
- package/dist/ontology-storage/unique-values.d.ts.map +1 -0
- package/dist/share-grant-storage.d.ts +2 -1
- package/dist/share-grant-storage.d.ts.map +1 -1
- package/dist/workflow-run-storage.d.ts +4 -0
- package/dist/workflow-run-storage.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/action-run-storage.ts +27 -0
- package/src/activity-storage.ts +588 -0
- package/src/agents/agent-storage.ts +11 -2
- package/src/agents/approvals.ts +456 -0
- package/src/agents/checkpoints.ts +9 -4
- package/src/agents/index.ts +1 -0
- package/src/agents/memory.ts +195 -0
- package/src/agents/messages.ts +21 -18
- package/src/agents/rows.ts +46 -1
- package/src/agents/runs.ts +202 -21
- package/src/agents/settings.ts +112 -0
- package/src/agents/threads.ts +412 -1
- package/src/ai-cost-groups.ts +11 -1
- package/src/ai-cost-storage.ts +54 -12
- package/src/ai-usage-storage.ts +79 -2
- package/src/artifact-storage.ts +553 -0
- package/src/auth-storage/auth-storage.ts +58 -26
- package/src/auth-storage/sessions.ts +27 -0
- package/src/auth-storage/users.ts +106 -60
- package/src/execution-storage.ts +95 -0
- package/src/index.ts +10 -0
- package/src/migrations/062-artifacts.sql +71 -0
- package/src/migrations/063-drop-output-diagnostics.sql +19 -0
- package/src/migrations/064-activity.sql +61 -0
- package/src/migrations/065-activity-timeline.sql +19 -0
- package/src/migrations/066-activity-interactions.sql +20 -0
- package/src/migrations/067-artifact-kinds.sql +32 -0
- package/src/migrations/068-artifact-state.sql +15 -0
- package/src/migrations/069-agent-thread-participants.sql +16 -0
- package/src/migrations/070-forked-context-checkpoints.sql +45 -0
- package/src/migrations/071-unique-values.sql +22 -0
- package/src/migrations/072-generated-media-usage.sql +32 -0
- package/src/migrations/073-model-call-files.sql +11 -0
- package/src/migrations/074-agent-memory.sql +32 -0
- package/src/migrations/075-artifact-threads.sql +21 -0
- package/src/migrations/076-agent-approvals.sql +59 -0
- package/src/migrations/077-agent-approval-resume.sql +20 -0
- package/src/migrations/078-subagent-threads.sql +241 -0
- package/src/migrations/079-subagent-questions.sql +6 -0
- package/src/migrations.ts +89 -1
- package/src/objects/README.md +7 -0
- package/src/objects/conditional-reader.ts +27 -0
- package/src/objects/query-compiler.ts +36 -6
- package/src/objects/read-scope.ts +140 -23
- package/src/objects/reader.ts +47 -14
- package/src/objects/scoped-reader.ts +103 -0
- package/src/objects/selected-reader.ts +12 -75
- package/src/objects/storage.ts +16 -0
- package/src/ontology-storage/index.ts +3 -0
- package/src/ontology-storage/materialization-writer.ts +14 -0
- package/src/ontology-storage/materializations.ts +16 -1
- package/src/ontology-storage/sources.ts +41 -0
- package/src/ontology-storage/unique-values.ts +187 -0
- package/src/share-grant-storage.ts +25 -0
- package/src/transactions.ts +1 -1
- package/src/workflow-run-storage.ts +27 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-- The Agent delivers files by publishing artifacts, so a run no longer collects an output
|
|
2
|
+
-- directory or reports on it. Stored `output_*` diagnostics go; a run left with none stores none.
|
|
3
|
+
UPDATE agent_runs
|
|
4
|
+
SET diagnostics = (
|
|
5
|
+
SELECT CASE WHEN count(*) = 0 THEN NULL ELSE json_group_array(json(value)) END
|
|
6
|
+
FROM (
|
|
7
|
+
SELECT value
|
|
8
|
+
FROM json_each(agent_runs.diagnostics)
|
|
9
|
+
WHERE json_extract(value, '$.code') NOT LIKE 'output\_%' ESCAPE '\'
|
|
10
|
+
ORDER BY key
|
|
11
|
+
)
|
|
12
|
+
)
|
|
13
|
+
WHERE diagnostics IS NOT NULL
|
|
14
|
+
AND json_valid(diagnostics)
|
|
15
|
+
AND EXISTS (
|
|
16
|
+
SELECT 1
|
|
17
|
+
FROM json_each(agent_runs.diagnostics)
|
|
18
|
+
WHERE json_extract(value, '$.code') LIKE 'output\_%' ESCAPE '\'
|
|
19
|
+
);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
-- App activity: one source per verified session, the visits it opened, and their page views.
|
|
2
|
+
-- Foreground activity moves a visit's `last_seen_at` and stores no row, unless it opens a visit.
|
|
3
|
+
-- A session id names an `auth_sessions` row for a user and a `share_sessions` row for a share; it
|
|
4
|
+
-- is not a secret, and no foreign key holds it, so history outlives its sessions. Timestamps are
|
|
5
|
+
-- ISO-8601 UTC text and compare lexicographically.
|
|
6
|
+
CREATE TABLE activity_sources (
|
|
7
|
+
project_id TEXT NOT NULL,
|
|
8
|
+
actor_type TEXT NOT NULL CHECK (actor_type IN ('user', 'share')),
|
|
9
|
+
session_id TEXT NOT NULL CHECK (length(session_id) > 0),
|
|
10
|
+
visit_id TEXT NOT NULL,
|
|
11
|
+
last_seen_at TEXT NOT NULL,
|
|
12
|
+
sequence INTEGER NOT NULL CHECK (sequence >= 0),
|
|
13
|
+
window_start TEXT NOT NULL,
|
|
14
|
+
window_count INTEGER NOT NULL CHECK (window_count >= 0),
|
|
15
|
+
PRIMARY KEY (project_id, actor_type, session_id)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
CREATE TABLE activity_visits (
|
|
19
|
+
project_id TEXT NOT NULL,
|
|
20
|
+
id TEXT NOT NULL,
|
|
21
|
+
actor_type TEXT NOT NULL CHECK (actor_type IN ('user', 'share')),
|
|
22
|
+
user_id TEXT,
|
|
23
|
+
grant_id TEXT,
|
|
24
|
+
session_id TEXT NOT NULL CHECK (length(session_id) > 0),
|
|
25
|
+
started_at TEXT NOT NULL,
|
|
26
|
+
last_seen_at TEXT NOT NULL CHECK (last_seen_at >= started_at),
|
|
27
|
+
page_views INTEGER NOT NULL CHECK (page_views >= 0),
|
|
28
|
+
attribution TEXT CHECK (attribution IS NULL OR json_type(attribution) = 'object'),
|
|
29
|
+
PRIMARY KEY (project_id, id),
|
|
30
|
+
CHECK (
|
|
31
|
+
(actor_type = 'user' AND user_id IS NOT NULL AND grant_id IS NULL)
|
|
32
|
+
OR (actor_type = 'share' AND user_id IS NULL AND grant_id IS NOT NULL)
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
-- A period reads the visits it overlaps. A visit lasts less than a day, so they started in
|
|
37
|
+
-- `[from - 1 day, to)`: both period indexes bound `started_at` on both sides. `last_seen_at` is
|
|
38
|
+
-- left out of every index, so the update each batch makes touches none of them. The user index
|
|
39
|
+
-- also serves deleting one user's history.
|
|
40
|
+
CREATE INDEX idx_activity_visits_started
|
|
41
|
+
ON activity_visits (project_id, started_at, id);
|
|
42
|
+
CREATE INDEX idx_activity_visits_user
|
|
43
|
+
ON activity_visits (project_id, user_id, started_at, id);
|
|
44
|
+
-- A session's visits, to join them with the session and the executions it authorized.
|
|
45
|
+
CREATE INDEX idx_activity_visits_session
|
|
46
|
+
ON activity_visits (project_id, actor_type, session_id);
|
|
47
|
+
|
|
48
|
+
CREATE TABLE activity_page_views (
|
|
49
|
+
project_id TEXT NOT NULL,
|
|
50
|
+
visit_id TEXT NOT NULL,
|
|
51
|
+
sequence INTEGER NOT NULL CHECK (sequence > 0),
|
|
52
|
+
id TEXT NOT NULL,
|
|
53
|
+
route TEXT NOT NULL,
|
|
54
|
+
received_at TEXT NOT NULL,
|
|
55
|
+
attribution TEXT CHECK (attribution IS NULL OR json_type(attribution) = 'object'),
|
|
56
|
+
PRIMARY KEY (project_id, visit_id, sequence),
|
|
57
|
+
FOREIGN KEY (project_id, visit_id) REFERENCES activity_visits (project_id, id) ON DELETE CASCADE
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
-- Finds a retried page view by the id its browser chose.
|
|
61
|
+
CREATE INDEX idx_activity_page_views_id ON activity_page_views (project_id, id);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-- A visit's timeline reads what its session started: the roots it authorized in a window, then
|
|
2
|
+
-- everything they caused. A signed-in session is the credential of its roots, a shared link's
|
|
3
|
+
-- session their delegation; a child names its parent. Agent executions copy their parent's
|
|
4
|
+
-- session: the root indexes hold only executions without a parent, so they never see those, and
|
|
5
|
+
-- end with `id` so the root read's order needs no sort.
|
|
6
|
+
CREATE INDEX idx_executions_session_roots
|
|
7
|
+
ON executions (project_id, authority_session_id, created_at, id)
|
|
8
|
+
WHERE authority_session_id IS NOT NULL AND parent_execution_id IS NULL;
|
|
9
|
+
CREATE INDEX idx_executions_delegation_roots
|
|
10
|
+
ON executions (project_id, authority_delegation_session_id, created_at, id)
|
|
11
|
+
WHERE authority_delegation_session_id IS NOT NULL AND parent_execution_id IS NULL;
|
|
12
|
+
CREATE INDEX idx_executions_parent
|
|
13
|
+
ON executions (project_id, parent_execution_id)
|
|
14
|
+
WHERE parent_execution_id IS NOT NULL;
|
|
15
|
+
|
|
16
|
+
-- A user's connection history lists all their sessions, revoked and expired ones too, newest
|
|
17
|
+
-- first.
|
|
18
|
+
CREATE INDEX idx_auth_sessions_user_created
|
|
19
|
+
ON auth_sessions (project_id, user_id, created_at, id);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- Interactions an app marks, such as a button: their name and route, never a value. They share
|
|
2
|
+
-- the visit's sequence with its page views, so a visit reads both in the order they happened, and
|
|
3
|
+
-- cascade with the visit, which counts them as it counts its page views.
|
|
4
|
+
ALTER TABLE activity_visits
|
|
5
|
+
ADD COLUMN interactions INTEGER NOT NULL DEFAULT 0 CHECK (interactions >= 0);
|
|
6
|
+
|
|
7
|
+
CREATE TABLE activity_interactions (
|
|
8
|
+
project_id TEXT NOT NULL,
|
|
9
|
+
visit_id TEXT NOT NULL,
|
|
10
|
+
sequence INTEGER NOT NULL CHECK (sequence > 0),
|
|
11
|
+
id TEXT NOT NULL,
|
|
12
|
+
name TEXT NOT NULL CHECK (length(name) BETWEEN 1 AND 100),
|
|
13
|
+
route TEXT NOT NULL,
|
|
14
|
+
received_at TEXT NOT NULL,
|
|
15
|
+
PRIMARY KEY (project_id, visit_id, sequence),
|
|
16
|
+
FOREIGN KEY (project_id, visit_id) REFERENCES activity_visits (project_id, id) ON DELETE CASCADE
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
-- Finds a retried interaction by the id its browser chose.
|
|
20
|
+
CREATE INDEX idx_activity_interactions_id ON activity_interactions (project_id, id);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
-- Artifacts take two more kinds: pages, and the canvases that lay pages out. SQLite cannot alter a
|
|
2
|
+
-- CHECK constraint, so the table is rebuilt; its versions and frame grants reference it by name.
|
|
3
|
+
CREATE TABLE artifacts_v2 (
|
|
4
|
+
project_id TEXT NOT NULL CHECK (length(trim(project_id)) > 0),
|
|
5
|
+
id TEXT NOT NULL CHECK (length(trim(id)) > 0),
|
|
6
|
+
kind TEXT NOT NULL CHECK (kind IN ('document', 'sheet', 'slides', 'page', 'canvas', 'file')),
|
|
7
|
+
title TEXT NOT NULL CHECK (length(trim(title)) > 0),
|
|
8
|
+
owner_principal_type TEXT NOT NULL
|
|
9
|
+
CHECK (owner_principal_type IN ('user', 'serviceAccount', 'system')),
|
|
10
|
+
owner_principal_id TEXT NOT NULL CHECK (length(owner_principal_id) > 0),
|
|
11
|
+
latest_version INTEGER NOT NULL CHECK (latest_version > 0),
|
|
12
|
+
next_version INTEGER NOT NULL CHECK (next_version > latest_version),
|
|
13
|
+
created_at TEXT NOT NULL,
|
|
14
|
+
updated_at TEXT NOT NULL,
|
|
15
|
+
PRIMARY KEY (project_id, id)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
INSERT INTO artifacts_v2 (
|
|
19
|
+
project_id, id, kind, title, owner_principal_type, owner_principal_id, latest_version,
|
|
20
|
+
next_version, created_at, updated_at
|
|
21
|
+
)
|
|
22
|
+
SELECT
|
|
23
|
+
project_id, id, kind, title, owner_principal_type, owner_principal_id, latest_version,
|
|
24
|
+
next_version, created_at, updated_at
|
|
25
|
+
FROM artifacts;
|
|
26
|
+
|
|
27
|
+
DROP TABLE artifacts;
|
|
28
|
+
ALTER TABLE artifacts_v2 RENAME TO artifacts;
|
|
29
|
+
|
|
30
|
+
CREATE INDEX idx_artifacts_project_updated ON artifacts (project_id, updated_at DESC, id);
|
|
31
|
+
CREATE INDEX idx_artifacts_owner_updated
|
|
32
|
+
ON artifacts (project_id, owner_principal_type, owner_principal_id, updated_at DESC, id);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
-- What a page keeps for each of its readers with `sixb.state`: JSON text by key, for one artifact
|
|
2
|
+
-- and one principal, across the artifact's versions. `size_bytes` is the value's UTF-8 length,
|
|
3
|
+
-- which the reader's limits sum. Deleting the artifact cascades here.
|
|
4
|
+
CREATE TABLE artifact_state (
|
|
5
|
+
project_id TEXT NOT NULL,
|
|
6
|
+
artifact_id TEXT NOT NULL,
|
|
7
|
+
principal_type TEXT NOT NULL CHECK (principal_type IN ('user', 'serviceAccount', 'system')),
|
|
8
|
+
principal_id TEXT NOT NULL CHECK (length(principal_id) > 0),
|
|
9
|
+
key TEXT NOT NULL CHECK (length(key) > 0),
|
|
10
|
+
value TEXT NOT NULL CHECK (json_valid(value)),
|
|
11
|
+
size_bytes INTEGER NOT NULL CHECK (size_bytes >= 0),
|
|
12
|
+
updated_at TEXT NOT NULL,
|
|
13
|
+
PRIMARY KEY (project_id, artifact_id, principal_type, principal_id, key),
|
|
14
|
+
FOREIGN KEY (project_id, artifact_id) REFERENCES artifacts (project_id, id) ON DELETE CASCADE
|
|
15
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
-- The users a thread's owner added to the conversation. Only users take part: only a signed-in
|
|
2
|
+
-- user talks to the Agent. Listing the threads shared with someone reads the principal index.
|
|
3
|
+
CREATE TABLE agent_thread_participants (
|
|
4
|
+
project_id TEXT NOT NULL,
|
|
5
|
+
thread_id TEXT NOT NULL,
|
|
6
|
+
principal_type TEXT NOT NULL CHECK (principal_type = 'user'),
|
|
7
|
+
principal_id TEXT NOT NULL CHECK (length(principal_id) > 0),
|
|
8
|
+
added_at TEXT NOT NULL,
|
|
9
|
+
added_by_type TEXT NOT NULL CHECK (added_by_type IN ('user', 'serviceAccount', 'system')),
|
|
10
|
+
added_by_id TEXT NOT NULL CHECK (length(added_by_id) > 0),
|
|
11
|
+
PRIMARY KEY (project_id, thread_id, principal_type, principal_id),
|
|
12
|
+
FOREIGN KEY (project_id, thread_id) REFERENCES agent_threads (project_id, id) ON DELETE CASCADE
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE INDEX idx_agent_thread_participants_principal
|
|
16
|
+
ON agent_thread_participants (project_id, principal_type, principal_id, thread_id);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
-- A forked thread copies the checkpoint its history needs, and the copy keeps the run that wrote
|
|
2
|
+
-- the summary. A run's checkpoint is therefore unique within a thread, not within the project.
|
|
3
|
+
-- SQLite cannot drop a UNIQUE constraint, so the table is rebuilt.
|
|
4
|
+
CREATE TABLE agent_context_checkpoints_v2 (
|
|
5
|
+
project_id TEXT NOT NULL,
|
|
6
|
+
id TEXT NOT NULL,
|
|
7
|
+
thread_id TEXT NOT NULL,
|
|
8
|
+
created_by_run_id TEXT NOT NULL,
|
|
9
|
+
previous_checkpoint_id TEXT,
|
|
10
|
+
reason TEXT NOT NULL CHECK (reason IN ('threshold', 'overflow')),
|
|
11
|
+
summary TEXT NOT NULL CHECK (length(trim(summary)) > 0),
|
|
12
|
+
summary_format_version INTEGER NOT NULL CHECK (summary_format_version = 1),
|
|
13
|
+
summarized_through_seq INTEGER NOT NULL CHECK (summarized_through_seq >= 1),
|
|
14
|
+
observed_head_seq INTEGER NOT NULL,
|
|
15
|
+
estimated_input_tokens_before INTEGER NOT NULL CHECK (estimated_input_tokens_before >= 0),
|
|
16
|
+
estimated_input_tokens_after INTEGER NOT NULL CHECK (estimated_input_tokens_after >= 0),
|
|
17
|
+
summary_model_id TEXT NOT NULL CHECK (length(trim(summary_model_id)) > 0),
|
|
18
|
+
created_at TEXT NOT NULL,
|
|
19
|
+
PRIMARY KEY (project_id, id),
|
|
20
|
+
UNIQUE (project_id, thread_id, created_by_run_id),
|
|
21
|
+
FOREIGN KEY (project_id, thread_id)
|
|
22
|
+
REFERENCES agent_threads(project_id, id) ON DELETE CASCADE,
|
|
23
|
+
FOREIGN KEY (project_id, created_by_run_id)
|
|
24
|
+
REFERENCES agent_runs(project_id, id) ON DELETE RESTRICT,
|
|
25
|
+
FOREIGN KEY (project_id, previous_checkpoint_id)
|
|
26
|
+
REFERENCES agent_context_checkpoints(project_id, id) ON DELETE RESTRICT,
|
|
27
|
+
CHECK (summarized_through_seq < observed_head_seq)
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
INSERT INTO agent_context_checkpoints_v2 (
|
|
31
|
+
project_id, id, thread_id, created_by_run_id, previous_checkpoint_id, reason, summary,
|
|
32
|
+
summary_format_version, summarized_through_seq, observed_head_seq,
|
|
33
|
+
estimated_input_tokens_before, estimated_input_tokens_after, summary_model_id, created_at
|
|
34
|
+
)
|
|
35
|
+
SELECT
|
|
36
|
+
project_id, id, thread_id, created_by_run_id, previous_checkpoint_id, reason, summary,
|
|
37
|
+
summary_format_version, summarized_through_seq, observed_head_seq,
|
|
38
|
+
estimated_input_tokens_before, estimated_input_tokens_after, summary_model_id, created_at
|
|
39
|
+
FROM agent_context_checkpoints;
|
|
40
|
+
|
|
41
|
+
DROP TABLE agent_context_checkpoints;
|
|
42
|
+
ALTER TABLE agent_context_checkpoints_v2 RENAME TO agent_context_checkpoints;
|
|
43
|
+
|
|
44
|
+
CREATE INDEX idx_agent_context_checkpoints_thread_latest
|
|
45
|
+
ON agent_context_checkpoints(project_id, thread_id, summarized_through_seq DESC, created_at DESC, id DESC);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
-- The values of unique properties, one row per value an object holds. Every object write keeps
|
|
2
|
+
-- them current, so a write that would give a value to a second object of the type is refused.
|
|
3
|
+
CREATE TABLE object_unique_values (
|
|
4
|
+
project_id TEXT NOT NULL,
|
|
5
|
+
object_type_id TEXT NOT NULL,
|
|
6
|
+
property_id TEXT NOT NULL,
|
|
7
|
+
value_key TEXT NOT NULL,
|
|
8
|
+
primary_id TEXT NOT NULL,
|
|
9
|
+
PRIMARY KEY (project_id, object_type_id, property_id, value_key)
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
-- The unique properties whose values were built from the objects already stored, and how their
|
|
13
|
+
-- keys were computed. A claim made with other keys is refused until they are built again.
|
|
14
|
+
CREATE TABLE object_unique_properties (
|
|
15
|
+
project_id TEXT NOT NULL,
|
|
16
|
+
object_type_id TEXT NOT NULL,
|
|
17
|
+
property_id TEXT NOT NULL,
|
|
18
|
+
key_kind TEXT NOT NULL,
|
|
19
|
+
key_version INTEGER NOT NULL,
|
|
20
|
+
prepared_at TEXT NOT NULL,
|
|
21
|
+
PRIMARY KEY (project_id, object_type_id, property_id)
|
|
22
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
ALTER TABLE ai_model_call_usage
|
|
2
|
+
ADD COLUMN image_output_tokens INTEGER
|
|
3
|
+
CHECK (image_output_tokens IS NULL OR image_output_tokens >= 0);
|
|
4
|
+
|
|
5
|
+
ALTER TABLE ai_model_call_usage
|
|
6
|
+
ADD COLUMN audio_output_tokens INTEGER
|
|
7
|
+
CHECK (audio_output_tokens IS NULL OR audio_output_tokens >= 0);
|
|
8
|
+
|
|
9
|
+
ALTER TABLE ai_model_call_usage
|
|
10
|
+
ADD COLUMN output_images INTEGER
|
|
11
|
+
CHECK (output_images IS NULL OR output_images >= 0);
|
|
12
|
+
|
|
13
|
+
ALTER TABLE ai_model_call_usage
|
|
14
|
+
ADD COLUMN input_characters INTEGER
|
|
15
|
+
CHECK (input_characters IS NULL OR input_characters >= 0);
|
|
16
|
+
|
|
17
|
+
-- SQLite cannot alter a CHECK constraint. Swapping the column avoids rebuilding a table that
|
|
18
|
+
-- usage groups, costs and limit reservations reference.
|
|
19
|
+
ALTER TABLE ai_model_call_usage
|
|
20
|
+
ADD COLUMN model_kind_next TEXT
|
|
21
|
+
CHECK (
|
|
22
|
+
model_kind_next IS NULL
|
|
23
|
+
OR model_kind_next IN (
|
|
24
|
+
'language', 'image', 'video', 'embedding', 'decision', 'transcription', 'speech', 'reranking'
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
UPDATE ai_model_call_usage SET model_kind_next = model_kind;
|
|
29
|
+
|
|
30
|
+
ALTER TABLE ai_model_call_usage DROP COLUMN model_kind;
|
|
31
|
+
|
|
32
|
+
ALTER TABLE ai_model_call_usage RENAME COLUMN model_kind_next TO model_kind;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
-- The files a model call produced. The execution that made the call decides who may read them.
|
|
2
|
+
CREATE TABLE ai_model_call_files (
|
|
3
|
+
project_id TEXT NOT NULL CHECK (length(trim(project_id)) > 0),
|
|
4
|
+
call_id TEXT NOT NULL CHECK (length(trim(call_id)) > 0),
|
|
5
|
+
execution_id TEXT NOT NULL CHECK (length(trim(execution_id)) > 0),
|
|
6
|
+
files TEXT NOT NULL CHECK (json_type(files) = 'array' AND json_array_length(files) > 0),
|
|
7
|
+
recorded_at TEXT NOT NULL,
|
|
8
|
+
PRIMARY KEY (project_id, call_id),
|
|
9
|
+
FOREIGN KEY (project_id, execution_id)
|
|
10
|
+
REFERENCES executions(project_id, id)
|
|
11
|
+
);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
-- Agent memory: each repo, 'user:<userId>' or 'project', is a log of revisions. A save inserts one
|
|
2
|
+
-- revision and the file versions it wrote, and never updates a row. A file's current contents are
|
|
3
|
+
-- its highest-revision version; NULL contents mean that revision deleted it. Timestamps are
|
|
4
|
+
-- ISO-8601 UTC text and compare lexicographically.
|
|
5
|
+
CREATE TABLE agent_memory_revisions (
|
|
6
|
+
project_id TEXT NOT NULL CHECK (length(trim(project_id)) > 0),
|
|
7
|
+
repo_id TEXT NOT NULL CHECK (length(trim(repo_id)) > 0),
|
|
8
|
+
revision INTEGER NOT NULL CHECK (revision > 0),
|
|
9
|
+
message TEXT NOT NULL CHECK (length(trim(message)) > 0),
|
|
10
|
+
author_principal_type TEXT NOT NULL
|
|
11
|
+
CHECK (author_principal_type IN ('user', 'serviceAccount', 'system')),
|
|
12
|
+
author_principal_id TEXT NOT NULL CHECK (length(author_principal_id) > 0),
|
|
13
|
+
source TEXT,
|
|
14
|
+
created_at TEXT NOT NULL,
|
|
15
|
+
PRIMARY KEY (project_id, repo_id, revision)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
-- A save also removes versions older than 90 days that are not their path's latest, so a
|
|
19
|
+
-- revision's rows here can be fewer than the files it wrote.
|
|
20
|
+
CREATE TABLE agent_memory_files (
|
|
21
|
+
project_id TEXT NOT NULL,
|
|
22
|
+
repo_id TEXT NOT NULL,
|
|
23
|
+
path TEXT NOT NULL CHECK (length(path) > 0),
|
|
24
|
+
revision INTEGER NOT NULL,
|
|
25
|
+
contents TEXT,
|
|
26
|
+
PRIMARY KEY (project_id, repo_id, path, revision),
|
|
27
|
+
FOREIGN KEY (project_id, repo_id, revision)
|
|
28
|
+
REFERENCES agent_memory_revisions (project_id, repo_id, revision) ON DELETE CASCADE
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
CREATE INDEX idx_agent_memory_files_revision
|
|
32
|
+
ON agent_memory_files (project_id, repo_id, revision);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
-- The threads an artifact is shared in: everyone who reads one of them reads the artifact. An
|
|
2
|
+
-- Agent turn publishing a version links its thread, for as long as a version from it remains; a
|
|
3
|
+
-- forked thread links its copies, `copied`, for as long as they last. Existing versions published
|
|
4
|
+
-- from a thread link it here.
|
|
5
|
+
CREATE TABLE artifact_threads (
|
|
6
|
+
project_id TEXT NOT NULL,
|
|
7
|
+
artifact_id TEXT NOT NULL,
|
|
8
|
+
thread_id TEXT NOT NULL CHECK (length(thread_id) > 0),
|
|
9
|
+
shared_at TEXT NOT NULL,
|
|
10
|
+
copied INTEGER NOT NULL DEFAULT 0 CHECK (copied IN (0, 1)),
|
|
11
|
+
PRIMARY KEY (project_id, artifact_id, thread_id),
|
|
12
|
+
FOREIGN KEY (project_id, artifact_id) REFERENCES artifacts (project_id, id) ON DELETE CASCADE
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
CREATE INDEX idx_artifact_threads_thread ON artifact_threads (project_id, thread_id, artifact_id);
|
|
16
|
+
|
|
17
|
+
INSERT INTO artifact_threads (project_id, artifact_id, thread_id, shared_at)
|
|
18
|
+
SELECT project_id, artifact_id, origin_thread_id, MIN(created_at)
|
|
19
|
+
FROM artifact_versions
|
|
20
|
+
WHERE origin_thread_id IS NOT NULL
|
|
21
|
+
GROUP BY project_id, artifact_id, origin_thread_id;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
-- Calls of the Agent that wait for whoever asked for the turn. A call's run id is its key: a
|
|
2
|
+
-- thread holds at most one pending, approved or denied approval per key, and a cancelled,
|
|
3
|
+
-- superseded or expired one lets the same call ask again. Timestamps are ISO-8601 UTC text and
|
|
4
|
+
-- compare lexicographically.
|
|
5
|
+
CREATE TABLE agent_approvals (
|
|
6
|
+
project_id TEXT NOT NULL,
|
|
7
|
+
id TEXT NOT NULL CHECK (length(trim(id)) > 0),
|
|
8
|
+
thread_id TEXT NOT NULL,
|
|
9
|
+
run_id TEXT NOT NULL CHECK (length(run_id) > 0),
|
|
10
|
+
caller_run_id TEXT NOT NULL CHECK (length(caller_run_id) > 0),
|
|
11
|
+
requested_by_type TEXT NOT NULL CHECK (requested_by_type IN ('user', 'serviceAccount', 'system')),
|
|
12
|
+
requested_by_id TEXT NOT NULL CHECK (length(requested_by_id) > 0),
|
|
13
|
+
mode TEXT NOT NULL CHECK (mode IN ('manual', 'accept-edits')),
|
|
14
|
+
call_key TEXT NOT NULL CHECK (length(call_key) > 0),
|
|
15
|
+
call TEXT NOT NULL,
|
|
16
|
+
status TEXT NOT NULL
|
|
17
|
+
CHECK (status IN ('pending', 'approved', 'denied', 'cancelled', 'superseded', 'expired')),
|
|
18
|
+
created_at TEXT NOT NULL,
|
|
19
|
+
expires_at TEXT NOT NULL,
|
|
20
|
+
decided_at TEXT,
|
|
21
|
+
decided_by_type TEXT CHECK (decided_by_type IN ('user', 'serviceAccount', 'system')),
|
|
22
|
+
decided_by_id TEXT,
|
|
23
|
+
outcome TEXT,
|
|
24
|
+
reported_in_message_id TEXT,
|
|
25
|
+
PRIMARY KEY (project_id, id),
|
|
26
|
+
FOREIGN KEY (project_id, thread_id) REFERENCES agent_threads (project_id, id) ON DELETE CASCADE
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
CREATE UNIQUE INDEX idx_agent_approvals_live_call
|
|
30
|
+
ON agent_approvals (project_id, thread_id, call_key)
|
|
31
|
+
WHERE status IN ('pending', 'approved', 'denied');
|
|
32
|
+
|
|
33
|
+
CREATE INDEX idx_agent_approvals_thread ON agent_approvals (project_id, thread_id, created_at);
|
|
34
|
+
CREATE INDEX idx_agent_approvals_run ON agent_approvals (project_id, run_id, status);
|
|
35
|
+
CREATE INDEX idx_agent_approvals_caller_run ON agent_approvals (project_id, caller_run_id, status);
|
|
36
|
+
CREATE INDEX idx_agent_approvals_requester
|
|
37
|
+
ON agent_approvals (project_id, requested_by_type, requested_by_id, status);
|
|
38
|
+
|
|
39
|
+
-- What each user lets the Agent change without asking: a default, then their own choice in a
|
|
40
|
+
-- thread. Absent rows fall back, in that order.
|
|
41
|
+
CREATE TABLE agent_user_settings (
|
|
42
|
+
project_id TEXT NOT NULL,
|
|
43
|
+
principal_type TEXT NOT NULL CHECK (principal_type IN ('user', 'serviceAccount', 'system')),
|
|
44
|
+
principal_id TEXT NOT NULL CHECK (length(principal_id) > 0),
|
|
45
|
+
approval_mode TEXT NOT NULL CHECK (approval_mode IN ('manual', 'accept-edits', 'auto')),
|
|
46
|
+
updated_at TEXT NOT NULL,
|
|
47
|
+
PRIMARY KEY (project_id, principal_type, principal_id)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
CREATE TABLE agent_thread_user_settings (
|
|
51
|
+
project_id TEXT NOT NULL,
|
|
52
|
+
thread_id TEXT NOT NULL,
|
|
53
|
+
principal_type TEXT NOT NULL CHECK (principal_type IN ('user', 'serviceAccount', 'system')),
|
|
54
|
+
principal_id TEXT NOT NULL CHECK (length(principal_id) > 0),
|
|
55
|
+
approval_mode TEXT NOT NULL CHECK (approval_mode IN ('manual', 'accept-edits', 'auto')),
|
|
56
|
+
updated_at TEXT NOT NULL,
|
|
57
|
+
PRIMARY KEY (project_id, thread_id, principal_type, principal_id),
|
|
58
|
+
FOREIGN KEY (project_id, thread_id) REFERENCES agent_threads (project_id, id) ON DELETE CASCADE
|
|
59
|
+
);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
-- A paused Agent turn resumes once its requester decided on every call it held. What that needs:
|
|
2
|
+
-- the mode "Always allow" raised the turn to, whether the turn may still resume on a call, and the
|
|
3
|
+
-- claim a process takes before it runs an approved call left without its outcome.
|
|
4
|
+
ALTER TABLE agent_approvals
|
|
5
|
+
ADD COLUMN raised_mode TEXT CHECK (raised_mode IN ('manual', 'accept-edits', 'auto'));
|
|
6
|
+
ALTER TABLE agent_approvals ADD COLUMN turn_stopped_at TEXT;
|
|
7
|
+
ALTER TABLE agent_approvals ADD COLUMN execution_claimed_at TEXT;
|
|
8
|
+
|
|
9
|
+
-- The repair pass: calls past their time, approved calls without an outcome, and decided calls of
|
|
10
|
+
-- turns that may still resume. Each index covers only the rows that are still work.
|
|
11
|
+
CREATE INDEX idx_agent_approvals_due
|
|
12
|
+
ON agent_approvals (project_id, expires_at)
|
|
13
|
+
WHERE status = 'pending';
|
|
14
|
+
CREATE INDEX idx_agent_approvals_unfinished
|
|
15
|
+
ON agent_approvals (project_id, created_at, id)
|
|
16
|
+
WHERE status = 'approved' AND outcome IS NULL;
|
|
17
|
+
CREATE INDEX idx_agent_approvals_resumable
|
|
18
|
+
ON agent_approvals (project_id, created_at, id)
|
|
19
|
+
WHERE status IN ('approved', 'denied') AND reported_in_message_id IS NULL
|
|
20
|
+
AND turn_stopped_at IS NULL;
|