@sixb/sqlite 0.1.11 → 0.1.12
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/README.md +32 -0
- package/dist/agents/rows.d.ts +2 -0
- package/dist/agents/rows.d.ts.map +1 -1
- package/dist/agents/threads.d.ts +2 -1
- package/dist/agents/threads.d.ts.map +1 -1
- package/dist/index.js +676 -61
- package/dist/index.js.map +18 -14
- package/dist/migrations.d.ts.map +1 -1
- package/dist/objects/query-compiler.d.ts +9 -2
- package/dist/objects/query-compiler.d.ts.map +1 -1
- package/dist/objects/read-scope.d.ts +3 -0
- package/dist/objects/read-scope.d.ts.map +1 -1
- package/dist/objects/reader.d.ts +1 -0
- package/dist/objects/reader.d.ts.map +1 -1
- package/dist/objects/rows.d.ts +1 -0
- package/dist/objects/rows.d.ts.map +1 -1
- package/dist/objects/storage.d.ts.map +1 -1
- package/dist/objects/vector-extension.d.ts +4 -0
- package/dist/objects/vector-extension.d.ts.map +1 -0
- package/dist/ontology-storage/index.d.ts +4 -0
- package/dist/ontology-storage/index.d.ts.map +1 -1
- package/dist/ontology-storage/materializations.d.ts +1 -0
- package/dist/ontology-storage/materializations.d.ts.map +1 -1
- package/dist/ontology-storage/vector-indexing.d.ts +20 -0
- package/dist/ontology-storage/vector-indexing.d.ts.map +1 -0
- package/dist/ontology-storage/vectors.d.ts +16 -0
- package/dist/ontology-storage/vectors.d.ts.map +1 -0
- package/dist/vector-encoding.d.ts +3 -0
- package/dist/vector-encoding.d.ts.map +1 -0
- package/package.json +8 -4
- package/src/agents/rows.ts +12 -0
- package/src/agents/threads.ts +41 -2
- package/src/ai-cost-storage.ts +4 -0
- package/src/migrations/041-agent-thread-workspaces.sql +2 -0
- package/src/migrations/042-vector-profiles.sql +21 -0
- package/src/migrations/043-vector-indexing.sql +197 -0
- package/src/migrations/044-vector-batching.sql +3 -0
- package/src/migrations/045-agent-thread-sandbox-state.sql +2 -0
- package/src/migrations.ts +14 -0
- package/src/objects/query-compiler.ts +105 -7
- package/src/objects/read-scope.ts +34 -31
- package/src/objects/reader.ts +25 -1
- package/src/objects/rows.ts +5 -1
- package/src/objects/storage.ts +12 -1
- package/src/objects/vector-extension.ts +26 -0
- package/src/ontology-storage/index.ts +16 -0
- package/src/ontology-storage/materializations.ts +13 -0
- package/src/ontology-storage/vector-indexing.ts +196 -0
- package/src/ontology-storage/vectors.ts +182 -0
- package/src/vector-encoding.ts +9 -0
package/dist/index.js
CHANGED
|
@@ -3990,6 +3990,246 @@ CREATE INDEX idx_ontology_outbox_publication_order
|
|
|
3990
3990
|
WHERE published_at IS NULL;
|
|
3991
3991
|
`;
|
|
3992
3992
|
|
|
3993
|
+
// src/migrations/041-agent-thread-workspaces.sql
|
|
3994
|
+
var _041_agent_thread_workspaces_default = `ALTER TABLE agent_threads ADD COLUMN sandbox_params TEXT
|
|
3995
|
+
CHECK (sandbox_params IS NULL OR (json_valid(sandbox_params) AND json_type(sandbox_params) = 'object'));
|
|
3996
|
+
`;
|
|
3997
|
+
|
|
3998
|
+
// src/migrations/042-vector-profiles.sql
|
|
3999
|
+
var _042_vector_profiles_default = `CREATE TABLE object_vectors (
|
|
4000
|
+
project_id TEXT NOT NULL,
|
|
4001
|
+
object_type_id TEXT NOT NULL,
|
|
4002
|
+
primary_id TEXT NOT NULL,
|
|
4003
|
+
profile TEXT NOT NULL CHECK (length(trim(profile)) > 0),
|
|
4004
|
+
configuration TEXT NOT NULL,
|
|
4005
|
+
source TEXT NOT NULL CHECK (
|
|
4006
|
+
json_valid(source) AND json_type(source) = 'array' AND json_array_length(source) > 0
|
|
4007
|
+
),
|
|
4008
|
+
source_fingerprint TEXT NOT NULL,
|
|
4009
|
+
embedding BLOB NOT NULL CHECK (
|
|
4010
|
+
typeof(embedding) = 'blob' AND length(embedding) BETWEEN 4 AND 64000
|
|
4011
|
+
AND length(embedding) % 4 = 0
|
|
4012
|
+
),
|
|
4013
|
+
last_commit_id TEXT NOT NULL,
|
|
4014
|
+
PRIMARY KEY (project_id, object_type_id, primary_id, profile),
|
|
4015
|
+
FOREIGN KEY (project_id, object_type_id, primary_id)
|
|
4016
|
+
REFERENCES objects (project_id, object_type_id, primary_id) ON DELETE CASCADE,
|
|
4017
|
+
FOREIGN KEY (project_id, last_commit_id)
|
|
4018
|
+
REFERENCES ontology_commits (project_id, id) DEFERRABLE INITIALLY DEFERRED
|
|
4019
|
+
);
|
|
4020
|
+
`;
|
|
4021
|
+
|
|
4022
|
+
// src/migrations/043-vector-indexing.sql
|
|
4023
|
+
var _043_vector_indexing_default = `CREATE TABLE object_vector_indexing (
|
|
4024
|
+
project_id TEXT NOT NULL,
|
|
4025
|
+
id TEXT NOT NULL,
|
|
4026
|
+
object_type_id TEXT NOT NULL,
|
|
4027
|
+
primary_id TEXT NOT NULL,
|
|
4028
|
+
profile TEXT NOT NULL,
|
|
4029
|
+
request TEXT NOT NULL,
|
|
4030
|
+
status TEXT NOT NULL CHECK (status IN ('pending', 'running', 'ready', 'failed')),
|
|
4031
|
+
available_at TEXT NOT NULL,
|
|
4032
|
+
dispatch_at TEXT NOT NULL,
|
|
4033
|
+
values_json TEXT,
|
|
4034
|
+
error TEXT,
|
|
4035
|
+
PRIMARY KEY (project_id, id),
|
|
4036
|
+
UNIQUE (project_id, object_type_id, primary_id, profile)
|
|
4037
|
+
);
|
|
4038
|
+
CREATE INDEX object_vector_indexing_due ON object_vector_indexing (project_id, dispatch_at, id)
|
|
4039
|
+
WHERE status <> 'failed';
|
|
4040
|
+
|
|
4041
|
+
CREATE TABLE executions_v2 (
|
|
4042
|
+
project_id TEXT NOT NULL CHECK (length(trim(project_id)) > 0),
|
|
4043
|
+
id TEXT NOT NULL CHECK (length(trim(id)) > 0),
|
|
4044
|
+
executor_kind TEXT NOT NULL CHECK (
|
|
4045
|
+
executor_kind IN (
|
|
4046
|
+
'request', 'action', 'pipeline', 'projection', 'rule', 'sync', 'webhook', 'workflow',
|
|
4047
|
+
'agent', 'kernel'
|
|
4048
|
+
)
|
|
4049
|
+
),
|
|
4050
|
+
executor_id TEXT NOT NULL CHECK (length(trim(executor_id)) > 0),
|
|
4051
|
+
source_kind TEXT NOT NULL CHECK (
|
|
4052
|
+
source_kind IN ('http', 'webhook', 'schedule', 'event', 'datasetVersion', 'execution', 'ontologyCommit')
|
|
4053
|
+
),
|
|
4054
|
+
source_id TEXT NOT NULL CHECK (length(trim(source_id)) > 0),
|
|
4055
|
+
requested_by_user_id TEXT,
|
|
4056
|
+
requested_by_service_account_id TEXT,
|
|
4057
|
+
correlation_id TEXT NOT NULL CHECK (length(trim(correlation_id)) > 0),
|
|
4058
|
+
parent_execution_id TEXT,
|
|
4059
|
+
authority_kind TEXT NOT NULL CHECK (
|
|
4060
|
+
authority_kind IN ('principal', 'trustedPrimitive', 'delegated', 'kernel', 'disabled')
|
|
4061
|
+
),
|
|
4062
|
+
authority_user_id TEXT,
|
|
4063
|
+
authority_service_account_id TEXT,
|
|
4064
|
+
authority_session_id TEXT,
|
|
4065
|
+
authority_access_token_id TEXT,
|
|
4066
|
+
authority_primitive_kind TEXT CHECK (
|
|
4067
|
+
authority_primitive_kind IS NULL
|
|
4068
|
+
OR authority_primitive_kind IN (
|
|
4069
|
+
'action', 'pipeline', 'projection', 'rule', 'sync', 'webhook', 'workflow'
|
|
4070
|
+
)
|
|
4071
|
+
),
|
|
4072
|
+
authority_primitive_id TEXT,
|
|
4073
|
+
authority_kernel_operation TEXT CHECK (
|
|
4074
|
+
authority_kernel_operation IS NULL OR authority_kernel_operation IN ('ontology.recover', 'ontology.indexVectors')
|
|
4075
|
+
),
|
|
4076
|
+
authority_delegation_kind TEXT CHECK (
|
|
4077
|
+
authority_delegation_kind IS NULL OR authority_delegation_kind = 'share'
|
|
4078
|
+
),
|
|
4079
|
+
authority_delegation_id TEXT,
|
|
4080
|
+
authority_delegation_session_id TEXT,
|
|
4081
|
+
requester_group_ids TEXT NOT NULL DEFAULT '[]',
|
|
4082
|
+
created_at TEXT NOT NULL,
|
|
4083
|
+
PRIMARY KEY (project_id, id),
|
|
4084
|
+
FOREIGN KEY (project_id, parent_execution_id) REFERENCES executions (project_id, id),
|
|
4085
|
+
FOREIGN KEY (project_id, requested_by_user_id) REFERENCES auth_users (project_id, id),
|
|
4086
|
+
FOREIGN KEY (project_id, requested_by_service_account_id)
|
|
4087
|
+
REFERENCES auth_service_accounts (project_id, id),
|
|
4088
|
+
FOREIGN KEY (project_id, authority_user_id) REFERENCES auth_users (project_id, id),
|
|
4089
|
+
FOREIGN KEY (project_id, authority_service_account_id)
|
|
4090
|
+
REFERENCES auth_service_accounts (project_id, id),
|
|
4091
|
+
FOREIGN KEY (project_id, authority_session_id) REFERENCES auth_sessions (project_id, id),
|
|
4092
|
+
FOREIGN KEY (project_id, authority_access_token_id)
|
|
4093
|
+
REFERENCES auth_access_tokens (project_id, id),
|
|
4094
|
+
FOREIGN KEY (
|
|
4095
|
+
project_id, authority_delegation_session_id, authority_delegation_id
|
|
4096
|
+
) REFERENCES share_sessions (project_id, id, grant_id),
|
|
4097
|
+
CHECK ((requested_by_user_id IS NOT NULL) + (requested_by_service_account_id IS NOT NULL) <= 1),
|
|
4098
|
+
CHECK (
|
|
4099
|
+
(source_kind = 'execution' AND parent_execution_id = source_id)
|
|
4100
|
+
OR (source_kind <> 'execution' AND parent_execution_id IS NULL)
|
|
4101
|
+
),
|
|
4102
|
+
CHECK (
|
|
4103
|
+
(
|
|
4104
|
+
authority_kind = 'principal'
|
|
4105
|
+
AND (authority_user_id IS NOT NULL) + (authority_service_account_id IS NOT NULL) = 1
|
|
4106
|
+
AND (authority_session_id IS NOT NULL) + (authority_access_token_id IS NOT NULL) <= 1
|
|
4107
|
+
AND (authority_session_id IS NULL OR authority_user_id IS NOT NULL)
|
|
4108
|
+
AND authority_primitive_kind IS NULL
|
|
4109
|
+
AND authority_primitive_id IS NULL
|
|
4110
|
+
AND authority_kernel_operation IS NULL
|
|
4111
|
+
AND authority_delegation_kind IS NULL
|
|
4112
|
+
AND authority_delegation_id IS NULL
|
|
4113
|
+
AND authority_delegation_session_id IS NULL
|
|
4114
|
+
)
|
|
4115
|
+
OR (
|
|
4116
|
+
authority_kind = 'trustedPrimitive'
|
|
4117
|
+
AND authority_user_id IS NULL
|
|
4118
|
+
AND authority_service_account_id IS NULL
|
|
4119
|
+
AND authority_session_id IS NULL
|
|
4120
|
+
AND authority_access_token_id IS NULL
|
|
4121
|
+
AND authority_primitive_kind IS NOT NULL
|
|
4122
|
+
AND authority_primitive_id IS NOT NULL
|
|
4123
|
+
AND length(trim(authority_primitive_id)) > 0
|
|
4124
|
+
AND authority_kernel_operation IS NULL
|
|
4125
|
+
AND authority_delegation_kind IS NULL
|
|
4126
|
+
AND authority_delegation_id IS NULL
|
|
4127
|
+
AND authority_delegation_session_id IS NULL
|
|
4128
|
+
)
|
|
4129
|
+
OR (
|
|
4130
|
+
authority_kind = 'delegated'
|
|
4131
|
+
AND authority_user_id IS NULL
|
|
4132
|
+
AND authority_service_account_id IS NULL
|
|
4133
|
+
AND authority_session_id IS NULL
|
|
4134
|
+
AND authority_access_token_id IS NULL
|
|
4135
|
+
AND authority_primitive_kind IS NULL
|
|
4136
|
+
AND authority_primitive_id IS NULL
|
|
4137
|
+
AND authority_kernel_operation IS NULL
|
|
4138
|
+
AND authority_delegation_kind IS NOT NULL
|
|
4139
|
+
AND authority_delegation_kind = 'share'
|
|
4140
|
+
AND authority_delegation_id IS NOT NULL
|
|
4141
|
+
AND length(trim(authority_delegation_id)) > 0
|
|
4142
|
+
AND authority_delegation_session_id IS NOT NULL
|
|
4143
|
+
AND length(trim(authority_delegation_session_id)) > 0
|
|
4144
|
+
)
|
|
4145
|
+
OR (
|
|
4146
|
+
authority_kind = 'kernel'
|
|
4147
|
+
AND authority_user_id IS NULL
|
|
4148
|
+
AND authority_service_account_id IS NULL
|
|
4149
|
+
AND authority_session_id IS NULL
|
|
4150
|
+
AND authority_access_token_id IS NULL
|
|
4151
|
+
AND authority_primitive_kind IS NULL
|
|
4152
|
+
AND authority_primitive_id IS NULL
|
|
4153
|
+
AND authority_kernel_operation IS NOT NULL
|
|
4154
|
+
AND authority_delegation_kind IS NULL
|
|
4155
|
+
AND authority_delegation_id IS NULL
|
|
4156
|
+
AND authority_delegation_session_id IS NULL
|
|
4157
|
+
)
|
|
4158
|
+
OR (
|
|
4159
|
+
authority_kind = 'disabled'
|
|
4160
|
+
AND authority_user_id IS NULL
|
|
4161
|
+
AND authority_service_account_id IS NULL
|
|
4162
|
+
AND authority_session_id IS NULL
|
|
4163
|
+
AND authority_access_token_id IS NULL
|
|
4164
|
+
AND authority_primitive_kind IS NULL
|
|
4165
|
+
AND authority_primitive_id IS NULL
|
|
4166
|
+
AND authority_kernel_operation IS NULL
|
|
4167
|
+
AND authority_delegation_kind IS NULL
|
|
4168
|
+
AND authority_delegation_id IS NULL
|
|
4169
|
+
AND authority_delegation_session_id IS NULL
|
|
4170
|
+
)
|
|
4171
|
+
),
|
|
4172
|
+
CHECK (
|
|
4173
|
+
(
|
|
4174
|
+
executor_kind = 'request'
|
|
4175
|
+
AND source_kind = 'http'
|
|
4176
|
+
AND executor_id = source_id
|
|
4177
|
+
AND (
|
|
4178
|
+
(
|
|
4179
|
+
authority_kind = 'principal'
|
|
4180
|
+
AND requested_by_user_id IS authority_user_id
|
|
4181
|
+
AND requested_by_service_account_id IS authority_service_account_id
|
|
4182
|
+
)
|
|
4183
|
+
OR (
|
|
4184
|
+
authority_kind IN ('delegated', 'disabled')
|
|
4185
|
+
AND requested_by_user_id IS NULL
|
|
4186
|
+
AND requested_by_service_account_id IS NULL
|
|
4187
|
+
)
|
|
4188
|
+
)
|
|
4189
|
+
)
|
|
4190
|
+
OR (
|
|
4191
|
+
executor_kind IN ('action', 'pipeline', 'projection', 'rule', 'sync', 'webhook', 'workflow')
|
|
4192
|
+
AND authority_kind = 'trustedPrimitive'
|
|
4193
|
+
AND executor_kind = authority_primitive_kind
|
|
4194
|
+
)
|
|
4195
|
+
OR (
|
|
4196
|
+
executor_kind = 'agent'
|
|
4197
|
+
AND source_kind = 'execution'
|
|
4198
|
+
AND (
|
|
4199
|
+
(
|
|
4200
|
+
authority_kind = 'principal'
|
|
4201
|
+
AND authority_service_account_id IS NOT NULL
|
|
4202
|
+
AND authority_session_id IS NULL
|
|
4203
|
+
AND authority_access_token_id IS NULL
|
|
4204
|
+
)
|
|
4205
|
+
OR (
|
|
4206
|
+
authority_kind = 'principal'
|
|
4207
|
+
AND authority_user_id IS NOT NULL
|
|
4208
|
+
AND (authority_session_id IS NOT NULL) + (authority_access_token_id IS NOT NULL) = 1
|
|
4209
|
+
)
|
|
4210
|
+
OR authority_kind = 'disabled'
|
|
4211
|
+
)
|
|
4212
|
+
)
|
|
4213
|
+
OR (executor_kind = 'kernel' AND authority_kind = 'kernel')
|
|
4214
|
+
)
|
|
4215
|
+
);
|
|
4216
|
+
|
|
4217
|
+
INSERT INTO executions_v2 (project_id, id, executor_kind, executor_id, source_kind, source_id, requested_by_user_id, requested_by_service_account_id, correlation_id, parent_execution_id, authority_kind, authority_user_id, authority_service_account_id, authority_session_id, authority_access_token_id, authority_primitive_kind, authority_primitive_id, authority_kernel_operation, authority_delegation_kind, authority_delegation_id, authority_delegation_session_id, requester_group_ids, created_at) SELECT project_id, id, executor_kind, executor_id, source_kind, source_id, requested_by_user_id, requested_by_service_account_id, correlation_id, parent_execution_id, authority_kind, authority_user_id, authority_service_account_id, authority_session_id, authority_access_token_id, authority_primitive_kind, authority_primitive_id, authority_kernel_operation, authority_delegation_kind, authority_delegation_id, authority_delegation_session_id, requester_group_ids, created_at FROM executions;
|
|
4218
|
+
DROP TABLE executions;
|
|
4219
|
+
ALTER TABLE executions_v2 RENAME TO executions;
|
|
4220
|
+
`;
|
|
4221
|
+
|
|
4222
|
+
// src/migrations/044-vector-batching.sql
|
|
4223
|
+
var _044_vector_batching_default = `ALTER TABLE object_vector_indexing ADD COLUMN batch_id TEXT;
|
|
4224
|
+
CREATE INDEX object_vector_indexing_batch ON object_vector_indexing (project_id, batch_id, id)
|
|
4225
|
+
WHERE batch_id IS NOT NULL;
|
|
4226
|
+
`;
|
|
4227
|
+
|
|
4228
|
+
// src/migrations/045-agent-thread-sandbox-state.sql
|
|
4229
|
+
var _045_agent_thread_sandbox_state_default = `ALTER TABLE agent_threads ADD COLUMN sandbox_state TEXT
|
|
4230
|
+
CHECK (sandbox_state IS NULL OR (json_valid(sandbox_state) AND json_type(sandbox_state) = 'object'));
|
|
4231
|
+
`;
|
|
4232
|
+
|
|
3993
4233
|
// src/migrations/037-execution-requester-groups.sql
|
|
3994
4234
|
var _037_execution_requester_groups_default = `ALTER TABLE executions ADD COLUMN requester_group_ids TEXT NOT NULL DEFAULT '[]';
|
|
3995
4235
|
|
|
@@ -4146,7 +4386,12 @@ var sqliteStorageMigrations = defineMigrations({
|
|
|
4146
4386
|
sqliteSql("037-execution-requester-groups", _037_execution_requester_groups_default),
|
|
4147
4387
|
sqliteSql("038-projection-source-roots", _038_projection_source_roots_default),
|
|
4148
4388
|
sqliteSql("039-connector-optional-pkce", _039_connector_optional_pkce_default),
|
|
4149
|
-
sqliteSql("040-outbox-publication-order", _040_outbox_publication_order_default)
|
|
4389
|
+
sqliteSql("040-outbox-publication-order", _040_outbox_publication_order_default),
|
|
4390
|
+
sqliteSql("041-agent-thread-workspaces", _041_agent_thread_workspaces_default),
|
|
4391
|
+
sqliteSql("042-vector-profiles", _042_vector_profiles_default),
|
|
4392
|
+
sqliteSql("043-vector-indexing", _043_vector_indexing_default),
|
|
4393
|
+
sqliteSql("044-vector-batching", _044_vector_batching_default),
|
|
4394
|
+
sqliteSql("045-agent-thread-sandbox-state", _045_agent_thread_sandbox_state_default)
|
|
4150
4395
|
]
|
|
4151
4396
|
});
|
|
4152
4397
|
function sqliteStoragePath(basePath) {
|
|
@@ -4831,6 +5076,7 @@ import {
|
|
|
4831
5076
|
} from "@sixb/core/storage";
|
|
4832
5077
|
|
|
4833
5078
|
// src/agents/rows.ts
|
|
5079
|
+
import { snapshotAgentThreadSandboxParams } from "@sixb/core/internal/agent-run-storage-provider";
|
|
4834
5080
|
import { parseSixbFailure } from "@sixb/core/internal/errors";
|
|
4835
5081
|
import {
|
|
4836
5082
|
AGENT_RUN_FAILURE_CODES,
|
|
@@ -4842,6 +5088,10 @@ function rowToThreadRecord(row) {
|
|
|
4842
5088
|
projectId: row.project_id,
|
|
4843
5089
|
ownerPrincipal: { type: row.owner_principal_type, id: row.owner_principal_id },
|
|
4844
5090
|
title: row.title ?? undefined,
|
|
5091
|
+
...row.sandbox_state == null ? {} : {
|
|
5092
|
+
sandboxState: JSON.parse(row.sandbox_state)
|
|
5093
|
+
},
|
|
5094
|
+
...row.sandbox_params == null ? {} : { sandboxParams: snapshotAgentThreadSandboxParams(JSON.parse(row.sandbox_params)) },
|
|
4845
5095
|
status: row.status,
|
|
4846
5096
|
activeRunId: row.active_run_id,
|
|
4847
5097
|
lastMessageAt: row.last_message_at ? new Date(row.last_message_at) : undefined,
|
|
@@ -5541,6 +5791,10 @@ class SqliteAgentRunStore {
|
|
|
5541
5791
|
}
|
|
5542
5792
|
|
|
5543
5793
|
// src/agents/threads.ts
|
|
5794
|
+
import {
|
|
5795
|
+
snapshotAgentThreadSandboxParams as snapshotAgentThreadSandboxParams2,
|
|
5796
|
+
transitionAgentThreadSandbox
|
|
5797
|
+
} from "@sixb/core/internal/agent-run-storage-provider";
|
|
5544
5798
|
import {
|
|
5545
5799
|
AgentStorageError as AgentStorageError4
|
|
5546
5800
|
} from "@sixb/core/storage";
|
|
@@ -5549,7 +5803,17 @@ class SqliteAgentThreadStore {
|
|
|
5549
5803
|
constructor(db) {
|
|
5550
5804
|
this.db = db;
|
|
5551
5805
|
}
|
|
5806
|
+
async transitionSandbox(input) {
|
|
5807
|
+
return this.db.transaction(() => {
|
|
5808
|
+
const run = input.action === "recreate" ? null : this.db.query("SELECT * FROM agent_runs WHERE project_id = ? AND id = ?").get(input.projectId, input.runId);
|
|
5809
|
+
const thread = this.requireThread(input.projectId, input.id);
|
|
5810
|
+
const state = transitionAgentThreadSandbox(thread, run ? rowToRunRecord(run) : null, input);
|
|
5811
|
+
this.db.query("UPDATE agent_threads SET sandbox_state = ? WHERE project_id = ? AND id = ?").run(JSON.stringify(state), input.projectId, input.id);
|
|
5812
|
+
return state;
|
|
5813
|
+
}).immediate();
|
|
5814
|
+
}
|
|
5552
5815
|
async create(input) {
|
|
5816
|
+
const sandboxParams = input.sandboxParams === undefined ? null : JSON.stringify(snapshotAgentThreadSandboxParams2(input.sandboxParams));
|
|
5553
5817
|
const createdAt = input.createdAt ?? new Date;
|
|
5554
5818
|
const updatedAt = input.updatedAt ?? createdAt;
|
|
5555
5819
|
try {
|
|
@@ -5560,14 +5824,15 @@ class SqliteAgentThreadStore {
|
|
|
5560
5824
|
owner_principal_type,
|
|
5561
5825
|
owner_principal_id,
|
|
5562
5826
|
title,
|
|
5827
|
+
sandbox_params,
|
|
5563
5828
|
status,
|
|
5564
5829
|
active_run_id,
|
|
5565
5830
|
last_message_at,
|
|
5566
5831
|
message_count,
|
|
5567
5832
|
created_at,
|
|
5568
5833
|
updated_at
|
|
5569
|
-
) VALUES (?, ?, ?, ?, ?, ?, NULL, NULL, 0, ?, ?)
|
|
5570
|
-
`).run(input.projectId, input.id, input.ownerPrincipal.type, input.ownerPrincipal.id, input.title ?? null, input.status ?? "active", createdAt.toISOString(), updatedAt.toISOString());
|
|
5834
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, NULL, NULL, 0, ?, ?)
|
|
5835
|
+
`).run(input.projectId, input.id, input.ownerPrincipal.type, input.ownerPrincipal.id, input.title ?? null, sandboxParams, input.status ?? "active", createdAt.toISOString(), updatedAt.toISOString());
|
|
5571
5836
|
} catch (error) {
|
|
5572
5837
|
if (isUniqueConstraintError2(error)) {
|
|
5573
5838
|
throw new AgentStorageError4("duplicate_id", `[SixbSqlite] Agent thread '${input.id}' already exists for project '${input.projectId}'.`);
|
|
@@ -6188,6 +6453,8 @@ var SQLITE_ACCOUNTING_OVERVIEW_SQL = `
|
|
|
6188
6453
|
CAST(COUNT(*) AS TEXT) AS model_call_count,
|
|
6189
6454
|
CAST(SUM(CASE WHEN reporting_status <> 'unavailable' THEN 1 ELSE 0 END) AS TEXT)
|
|
6190
6455
|
AS reported_usage_call_count,
|
|
6456
|
+
CAST(SUM(CASE WHEN input_tokens IS NOT NULL AND output_tokens IS NOT NULL THEN 1 ELSE 0 END) AS TEXT)
|
|
6457
|
+
AS complete_usage_call_count,
|
|
6191
6458
|
CAST(COUNT(input_tokens) AS TEXT) AS input_tokens_count,
|
|
6192
6459
|
CAST(SUM(input_tokens) AS TEXT) AS input_tokens_sum,
|
|
6193
6460
|
CAST(COUNT(output_tokens) AS TEXT) AS output_tokens_count,
|
|
@@ -6240,6 +6507,7 @@ function aggregateFragmentFromRow(row) {
|
|
|
6240
6507
|
modelCallCount: row.model_call_count,
|
|
6241
6508
|
usage: {
|
|
6242
6509
|
reportedCallCount: row.reported_usage_call_count,
|
|
6510
|
+
completeCallCount: row.complete_usage_call_count,
|
|
6243
6511
|
inputTokens: meterFragment(row.input_tokens_count, row.input_tokens_sum),
|
|
6244
6512
|
outputTokens: meterFragment(row.output_tokens_count, row.output_tokens_sum),
|
|
6245
6513
|
uncachedInputTokens: meterFragment(row.uncached_input_tokens_count, row.uncached_input_tokens_sum),
|
|
@@ -9652,13 +9920,37 @@ function isDuplicateExecutionError(error) {
|
|
|
9652
9920
|
return error instanceof Error && error.message.includes("UNIQUE constraint failed: executions.project_id, executions.id");
|
|
9653
9921
|
}
|
|
9654
9922
|
|
|
9923
|
+
// src/objects/storage.ts
|
|
9924
|
+
import { hasVectorProfile as hasVectorProfile3 } from "@sixb/core/internal/query";
|
|
9925
|
+
|
|
9655
9926
|
// src/objects/query-compiler.ts
|
|
9656
9927
|
import {
|
|
9657
9928
|
ObjectQueryExecutionError
|
|
9658
9929
|
} from "@sixb/core";
|
|
9930
|
+
import {
|
|
9931
|
+
hasVectorProfile,
|
|
9932
|
+
isVectorProfileQuery,
|
|
9933
|
+
normalizeVector,
|
|
9934
|
+
vectorSearchCandidateLimit
|
|
9935
|
+
} from "@sixb/core/internal/query";
|
|
9936
|
+
|
|
9937
|
+
// src/vector-encoding.ts
|
|
9938
|
+
function encodeSqliteVector(values) {
|
|
9939
|
+
const bytes = new Uint8Array(values.length * 4);
|
|
9940
|
+
const view = new DataView(bytes.buffer);
|
|
9941
|
+
for (let index = 0;index < values.length; index++) {
|
|
9942
|
+
view.setFloat32(index * 4, values[index], true);
|
|
9943
|
+
}
|
|
9944
|
+
return bytes;
|
|
9945
|
+
}
|
|
9946
|
+
|
|
9947
|
+
// src/objects/query-compiler.ts
|
|
9659
9948
|
var PAGE_TOKEN_PREFIX = "keyset:";
|
|
9660
9949
|
var DEFAULT_EXPANSION_FANOUT = 1000;
|
|
9661
9950
|
function compileObjectQuery(projectId, query, options = {}) {
|
|
9951
|
+
if (hasVectorProfile(query) && !isVectorProfileQuery(query)) {
|
|
9952
|
+
throw new ObjectQueryExecutionError("unsupported_vector_composition", "Vector search supports one profile with filters before ranking and limit/project after.");
|
|
9953
|
+
}
|
|
9662
9954
|
const source = options.source ?? DEFAULT_OBJECT_QUERY_SOURCE;
|
|
9663
9955
|
const ctx = { probeLimit: options.includeTotal === false, source };
|
|
9664
9956
|
return source.wrapQuery(compileObjectQueryInternal(projectId, query, ctx));
|
|
@@ -9697,8 +9989,59 @@ function compileObjectQueryInternal(projectId, query, ctx) {
|
|
|
9697
9989
|
case "expand":
|
|
9698
9990
|
return compileExpand(projectId, query.input, query.expansions, ctx);
|
|
9699
9991
|
case "vector":
|
|
9700
|
-
|
|
9701
|
-
}
|
|
9992
|
+
return compileVector(projectId, query, ctx);
|
|
9993
|
+
}
|
|
9994
|
+
}
|
|
9995
|
+
function compileVector(projectId, query, ctx) {
|
|
9996
|
+
if (typeof query.vector === "string" || !isVectorProfileQuery(query) || !query.configuration || !Number.isSafeInteger(query.k) || query.k < 1 || query.k > 1000 || query.vector.length < 1 || query.vector.length > 16000) {
|
|
9997
|
+
throw new ObjectQueryExecutionError("invalid_vector_query", "A validated named vector profile is required.");
|
|
9998
|
+
}
|
|
9999
|
+
const input = compileObjectQueryInternal(projectId, query.input, exactContext(ctx));
|
|
10000
|
+
const permissions = ctx.source.objectPropertyPermissionsTable;
|
|
10001
|
+
const permissionJoin = permissions ? `CROSS JOIN (
|
|
10002
|
+
SELECT project_id, object_type_id, primary_id, json_group_array(property_id) AS property_ids
|
|
10003
|
+
FROM ${permissions}
|
|
10004
|
+
GROUP BY project_id, object_type_id, primary_id
|
|
10005
|
+
) AS vector_permissions ON vector_permissions.project_id = vectors.project_id
|
|
10006
|
+
AND vector_permissions.object_type_id = vectors.object_type_id
|
|
10007
|
+
AND vector_permissions.primary_id = vectors.primary_id` : "";
|
|
10008
|
+
const authorized = permissions ? `AND NOT EXISTS (
|
|
10009
|
+
SELECT 1 FROM json_each(vectors.source) AS required
|
|
10010
|
+
WHERE required.value NOT IN (SELECT value FROM json_each(vector_permissions.property_ids))
|
|
10011
|
+
)` : "";
|
|
10012
|
+
const candidates = `FROM (${input.sql}) AS input
|
|
10013
|
+
CROSS JOIN object_vectors AS vectors ON vectors.project_id = input.project_id
|
|
10014
|
+
AND vectors.object_type_id = input.object_type_id AND vectors.primary_id = input.primary_id
|
|
10015
|
+
${permissionJoin}
|
|
10016
|
+
WHERE vectors.profile = ? AND vectors.configuration = ?
|
|
10017
|
+
AND length(vectors.embedding) / 4 = ? ${authorized}`;
|
|
10018
|
+
const candidateArgs = [...input.args, query.profile, query.configuration, query.vector.length];
|
|
10019
|
+
const limit = vectorSearchCandidateLimit(query.vector.length);
|
|
10020
|
+
const values = normalizeVector(query.vector, query.vector.length);
|
|
10021
|
+
const order = compileOrder([
|
|
10022
|
+
{ kind: "column", column: "_vector_score", direction: "desc" },
|
|
10023
|
+
...identityOrderFields().map((field) => ({ ...field, binary: true }))
|
|
10024
|
+
]);
|
|
10025
|
+
const sql = `SELECT * FROM (SELECT input.*, max(-1, min(1, 1 - vec_distance_cosine(vectors.embedding, ?))) AS _vector_score
|
|
10026
|
+
${candidates}) AS ranked ORDER BY ${order.sql} LIMIT ?`;
|
|
10027
|
+
const args = [encodeSqliteVector(values), ...candidateArgs, query.k];
|
|
10028
|
+
return {
|
|
10029
|
+
sql,
|
|
10030
|
+
args,
|
|
10031
|
+
totalSql: `SELECT COUNT(*) AS total FROM (SELECT 1 ${candidates} LIMIT ?) AS eligible`,
|
|
10032
|
+
totalArgs: [...candidateArgs, query.k],
|
|
10033
|
+
order,
|
|
10034
|
+
vectorProbe: {
|
|
10035
|
+
sql: `SELECT COUNT(*) AS total FROM (SELECT 1 ${candidates} LIMIT ?) AS candidates`,
|
|
10036
|
+
args: [...candidateArgs, limit + 1],
|
|
10037
|
+
limit
|
|
10038
|
+
},
|
|
10039
|
+
hasMore: () => false,
|
|
10040
|
+
trimRows: identityRows,
|
|
10041
|
+
nextPageToken: () => {
|
|
10042
|
+
return;
|
|
10043
|
+
}
|
|
10044
|
+
};
|
|
9702
10045
|
}
|
|
9703
10046
|
function compileStart(projectId, query, ctx) {
|
|
9704
10047
|
if (query.includeSubtypes === true) {
|
|
@@ -9788,6 +10131,7 @@ function compileWhere(projectId, inputQuery, predicate, ctx) {
|
|
|
9788
10131
|
WHERE ${predicate.sql}
|
|
9789
10132
|
`,
|
|
9790
10133
|
totalArgs: [...input.args, ...predicate.args],
|
|
10134
|
+
vectorProbe: input.vectorProbe,
|
|
9791
10135
|
order: input.order,
|
|
9792
10136
|
hasMore: () => false,
|
|
9793
10137
|
trimRows: identityRows,
|
|
@@ -9818,7 +10162,7 @@ function compileSort(projectId, inputQuery, fields, ctx) {
|
|
|
9818
10162
|
input.created_at,
|
|
9819
10163
|
input.updated_at,
|
|
9820
10164
|
input.version,
|
|
9821
|
-
input.last_commit_id
|
|
10165
|
+
input.last_commit_id${input.vectorProbe ? ", input._vector_score" : ""}
|
|
9822
10166
|
FROM (${input.sql}) AS input
|
|
9823
10167
|
ORDER BY ${order.sql}
|
|
9824
10168
|
`,
|
|
@@ -9849,6 +10193,7 @@ function compileLimit(projectId, inputQuery, rawLimit, ctx) {
|
|
|
9849
10193
|
FROM (${input.sql}) AS input
|
|
9850
10194
|
`,
|
|
9851
10195
|
totalArgs: input.args,
|
|
10196
|
+
vectorProbe: input.vectorProbe,
|
|
9852
10197
|
order: input.order,
|
|
9853
10198
|
hasMore: (rowCount, total) => total === undefined ? ctx.probeLimit && rowCount > limit : limit < total,
|
|
9854
10199
|
trimRows: ctx.probeLimit ? (rows) => rows.slice(0, limit) : identityRows,
|
|
@@ -9877,6 +10222,7 @@ function compilePage(projectId, inputQuery, rawPageSize, pageToken, ctx) {
|
|
|
9877
10222
|
FROM (${input.sql}) AS input
|
|
9878
10223
|
`,
|
|
9879
10224
|
totalArgs: input.args,
|
|
10225
|
+
vectorProbe: input.vectorProbe,
|
|
9880
10226
|
order: input.order,
|
|
9881
10227
|
hasMore: (rowCount) => rowCount > pageSize,
|
|
9882
10228
|
trimRows: (rows) => rows.slice(0, pageSize),
|
|
@@ -9953,6 +10299,7 @@ function compileExpand(projectId, inputQuery, expansions, ctx) {
|
|
|
9953
10299
|
args: [...expand.args, ...input.args, ...inputOrder.args],
|
|
9954
10300
|
totalSql: input.totalSql,
|
|
9955
10301
|
totalArgs: input.totalArgs,
|
|
10302
|
+
vectorProbe: input.vectorProbe,
|
|
9956
10303
|
order: input.order,
|
|
9957
10304
|
hasMoreProbe: input.hasMoreProbe,
|
|
9958
10305
|
hasMore: input.hasMore,
|
|
@@ -10123,13 +10470,14 @@ function compileProject(projectId, inputQuery, properties, ctx) {
|
|
|
10123
10470
|
input.created_at,
|
|
10124
10471
|
input.updated_at,
|
|
10125
10472
|
input.version,
|
|
10126
|
-
input.last_commit_id
|
|
10473
|
+
input.last_commit_id${input.vectorProbe ? ", input._vector_score" : ""}
|
|
10127
10474
|
FROM (${input.sql}) AS input
|
|
10128
10475
|
ORDER BY ${inputOrder.sql}
|
|
10129
10476
|
`,
|
|
10130
10477
|
args: [...projection.args, ...input.args, ...inputOrder.args],
|
|
10131
10478
|
totalSql: input.totalSql,
|
|
10132
10479
|
totalArgs: input.totalArgs,
|
|
10480
|
+
vectorProbe: input.vectorProbe,
|
|
10133
10481
|
order: outputOrder,
|
|
10134
10482
|
hasMoreProbe: input.hasMoreProbe,
|
|
10135
10483
|
hasMore: input.hasMore,
|
|
@@ -10324,7 +10672,7 @@ function compileOrder(fields, qualifier, propertyColumn = "properties") {
|
|
|
10324
10672
|
const args = [];
|
|
10325
10673
|
for (const field of fields) {
|
|
10326
10674
|
if (field.kind === "column") {
|
|
10327
|
-
clauses.push(`${columnExpression(field.column, qualifier)} ${field.direction.toUpperCase()}`);
|
|
10675
|
+
clauses.push(`${columnExpression(field.column, qualifier)}${field.binary ? " COLLATE BINARY" : ""} ${field.direction.toUpperCase()}`);
|
|
10328
10676
|
continue;
|
|
10329
10677
|
}
|
|
10330
10678
|
const direction = field.direction === "desc" ? "DESC" : "ASC";
|
|
@@ -10510,6 +10858,8 @@ function isPlainObject(value) {
|
|
|
10510
10858
|
}
|
|
10511
10859
|
|
|
10512
10860
|
// src/objects/reader.ts
|
|
10861
|
+
import { ObjectQueryExecutionError as ObjectQueryExecutionError3 } from "@sixb/core";
|
|
10862
|
+
import { hasVectorProfile as hasVectorProfile2 } from "@sixb/core/internal/query";
|
|
10513
10863
|
import { linkBatchKey, objectBatchKey } from "@sixb/core/storage";
|
|
10514
10864
|
|
|
10515
10865
|
// src/objects/rows.ts
|
|
@@ -10526,7 +10876,10 @@ function rowToObject(row) {
|
|
|
10526
10876
|
};
|
|
10527
10877
|
}
|
|
10528
10878
|
function queryRowToObject(row) {
|
|
10529
|
-
const base =
|
|
10879
|
+
const base = {
|
|
10880
|
+
...rowToObject(row),
|
|
10881
|
+
...row._vector_score === undefined ? {} : { score: row._vector_score }
|
|
10882
|
+
};
|
|
10530
10883
|
const links = reviveExpandedLinks(parseExpandColumn(row._expand));
|
|
10531
10884
|
return links ? { ...base, links } : base;
|
|
10532
10885
|
}
|
|
@@ -10589,6 +10942,25 @@ function isPlainObject2(value) {
|
|
|
10589
10942
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10590
10943
|
}
|
|
10591
10944
|
|
|
10945
|
+
// src/objects/vector-extension.ts
|
|
10946
|
+
import { ObjectQueryExecutionError as ObjectQueryExecutionError2 } from "@sixb/core";
|
|
10947
|
+
import { load } from "sqlite-vec";
|
|
10948
|
+
var loaded = new WeakSet;
|
|
10949
|
+
function ensureSqliteVectorSearch(db) {
|
|
10950
|
+
if (loaded.has(db))
|
|
10951
|
+
return;
|
|
10952
|
+
const options = db.query("PRAGMA compile_options").all();
|
|
10953
|
+
if (options.some((option) => option.compile_options === "OMIT_LOAD_EXTENSION")) {
|
|
10954
|
+
throw new ObjectQueryExecutionError2("vector_extension_missing", "SQLite vector search requires extension support. On macOS install SQLite (brew install sqlite), then call Database.setCustomSQLite with its library path before opening any database.");
|
|
10955
|
+
}
|
|
10956
|
+
try {
|
|
10957
|
+
load(db);
|
|
10958
|
+
loaded.add(db);
|
|
10959
|
+
} catch (cause) {
|
|
10960
|
+
throw new Error("[SixbSqlite] Could not load sqlite-vec for vector search. Check that its native package supports your platform.", { cause });
|
|
10961
|
+
}
|
|
10962
|
+
}
|
|
10963
|
+
|
|
10592
10964
|
// src/objects/reader.ts
|
|
10593
10965
|
class SqliteObjectReader {
|
|
10594
10966
|
db;
|
|
@@ -10597,7 +10969,21 @@ class SqliteObjectReader {
|
|
|
10597
10969
|
this.db = db;
|
|
10598
10970
|
this.source = source;
|
|
10599
10971
|
}
|
|
10972
|
+
assertVectorSearch(params) {
|
|
10973
|
+
if (!hasVectorProfile2(params.query))
|
|
10974
|
+
return;
|
|
10975
|
+
const compiled = compileObjectQuery(params.projectId, params.query, { source: this.source });
|
|
10976
|
+
if (!compiled.vectorProbe)
|
|
10977
|
+
return;
|
|
10978
|
+
ensureSqliteVectorSearch(this.db);
|
|
10979
|
+
const probe = compiled.vectorProbe;
|
|
10980
|
+
const row = this.db.query(probe.sql).get(...probe.args);
|
|
10981
|
+
if (Number(row?.total ?? 0) > probe.limit) {
|
|
10982
|
+
throw new ObjectQueryExecutionError3("vector_work_limit_exceeded", `Exact vector search supports at most ${probe.limit} eligible vectors at this dimension. Narrow the query filters.`);
|
|
10983
|
+
}
|
|
10984
|
+
}
|
|
10600
10985
|
queryObjects(params) {
|
|
10986
|
+
this.assertVectorSearch(params);
|
|
10601
10987
|
const source = this.source;
|
|
10602
10988
|
const compiled = compileObjectQuery(params.projectId, params.query, {
|
|
10603
10989
|
includeTotal: params.includeTotal,
|
|
@@ -10615,6 +11001,7 @@ class SqliteObjectReader {
|
|
|
10615
11001
|
};
|
|
10616
11002
|
}
|
|
10617
11003
|
countObjects(params) {
|
|
11004
|
+
this.assertVectorSearch(params);
|
|
10618
11005
|
const source = this.source;
|
|
10619
11006
|
return {
|
|
10620
11007
|
count: readTotal(this.db, compileObjectQuery(params.projectId, stripOuterRowShape(params.query), {
|
|
@@ -10623,6 +11010,7 @@ class SqliteObjectReader {
|
|
|
10623
11010
|
};
|
|
10624
11011
|
}
|
|
10625
11012
|
existsObjects(params) {
|
|
11013
|
+
this.assertVectorSearch(params);
|
|
10626
11014
|
const source = this.source;
|
|
10627
11015
|
const compiled = compileObjectQuery(params.projectId, existsProbeQuery(params.query), {
|
|
10628
11016
|
source
|
|
@@ -10630,6 +11018,7 @@ class SqliteObjectReader {
|
|
|
10630
11018
|
return { exists: this.db.query(compiled.sql).get(...compiled.args) !== null };
|
|
10631
11019
|
}
|
|
10632
11020
|
facetObjects(params) {
|
|
11021
|
+
this.assertVectorSearch(params);
|
|
10633
11022
|
const source = this.source;
|
|
10634
11023
|
const compiled = compileObjectQuery(params.projectId, stripOuterRowShape(params.query), {
|
|
10635
11024
|
source
|
|
@@ -10966,6 +11355,7 @@ ${sql}`,
|
|
|
10966
11355
|
wrapQuery: (query) => ({
|
|
10967
11356
|
...query,
|
|
10968
11357
|
...wrapStatement(query.sql, query.args),
|
|
11358
|
+
vectorProbe: query.vectorProbe ? { ...query.vectorProbe, ...wrapStatement(query.vectorProbe.sql, query.vectorProbe.args) } : undefined,
|
|
10969
11359
|
totalSql: `${compiled.sql}
|
|
10970
11360
|
${query.totalSql}`,
|
|
10971
11361
|
totalArgs: [...compiled.args, ...query.totalArgs],
|
|
@@ -11052,16 +11442,16 @@ function compileSelectedReadScopeCte(scopeJson, projectId) {
|
|
|
11052
11442
|
|
|
11053
11443
|
SELECT edge.project_id, selection.node_id, edge.target_type_id, edge.target_id
|
|
11054
11444
|
FROM _sixb_scope_reachable AS parent
|
|
11055
|
-
JOIN _sixb_scope_link_selections AS selection
|
|
11445
|
+
CROSS JOIN _sixb_scope_link_selections AS selection
|
|
11056
11446
|
ON selection.parent_node_id = parent.node_id
|
|
11057
11447
|
AND selection.source_object_type_id = parent.object_type_id
|
|
11058
|
-
JOIN links AS edge
|
|
11448
|
+
CROSS JOIN links AS edge
|
|
11059
11449
|
ON edge.project_id = parent.project_id
|
|
11060
11450
|
AND edge.source_type_id = parent.object_type_id
|
|
11061
11451
|
AND edge.source_id = parent.primary_id
|
|
11062
11452
|
AND edge.link_id = selection.link_id
|
|
11063
11453
|
AND edge.target_type_id = selection.target_object_type_id
|
|
11064
|
-
JOIN objects AS target
|
|
11454
|
+
CROSS JOIN objects AS target
|
|
11065
11455
|
ON target.project_id = edge.project_id
|
|
11066
11456
|
AND target.object_type_id = edge.target_type_id
|
|
11067
11457
|
AND target.primary_id = edge.target_id
|
|
@@ -11082,32 +11472,29 @@ function compileSelectedReadScopeCte(scopeJson, projectId) {
|
|
|
11082
11472
|
SELECT DISTINCT project_id, object_type_id, primary_id
|
|
11083
11473
|
FROM _sixb_scope_reachable
|
|
11084
11474
|
),
|
|
11475
|
+
_sixb_scope_object_grants AS (
|
|
11476
|
+
SELECT reachable.project_id, reachable.object_type_id, reachable.primary_id,
|
|
11477
|
+
json_group_array(DISTINCT selected_property.value) FILTER (WHERE selected_property.value IS NOT NULL) AS property_ids
|
|
11478
|
+
FROM _sixb_scope_reachable AS reachable
|
|
11479
|
+
LEFT JOIN _sixb_scope_object_selections AS selection
|
|
11480
|
+
ON selection.node_id = reachable.node_id
|
|
11481
|
+
AND selection.object_type_id = reachable.object_type_id
|
|
11482
|
+
LEFT JOIN json_each(selection.property_ids) AS selected_property ON true
|
|
11483
|
+
GROUP BY reachable.project_id, reachable.object_type_id, reachable.primary_id
|
|
11484
|
+
),
|
|
11085
11485
|
_sixb_scope_objects AS (
|
|
11086
|
-
SELECT
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
AND permission.property_id = property.key
|
|
11099
|
-
),
|
|
11100
|
-
json('{}')
|
|
11101
|
-
) AS properties,
|
|
11102
|
-
stored.created_at,
|
|
11103
|
-
stored.updated_at,
|
|
11104
|
-
stored.version,
|
|
11105
|
-
stored.last_commit_id
|
|
11106
|
-
FROM objects AS stored
|
|
11107
|
-
JOIN _sixb_scope_object_ids AS visible
|
|
11108
|
-
ON visible.project_id = stored.project_id
|
|
11109
|
-
AND visible.object_type_id = stored.object_type_id
|
|
11110
|
-
AND visible.primary_id = stored.primary_id
|
|
11486
|
+
SELECT stored.project_id, stored.object_type_id, stored.primary_id,
|
|
11487
|
+
COALESCE((
|
|
11488
|
+
SELECT json_group_object(property.key, ${sqliteJsonEachValue("property")})
|
|
11489
|
+
FROM json_each(stored.properties) AS property
|
|
11490
|
+
WHERE property.key IN (SELECT value FROM json_each(grants.property_ids))
|
|
11491
|
+
), json('{}')) AS properties,
|
|
11492
|
+
stored.created_at, stored.updated_at, stored.version, stored.last_commit_id
|
|
11493
|
+
FROM _sixb_scope_object_grants AS grants
|
|
11494
|
+
CROSS JOIN objects AS stored
|
|
11495
|
+
ON stored.project_id = grants.project_id
|
|
11496
|
+
AND stored.object_type_id = grants.object_type_id
|
|
11497
|
+
AND stored.primary_id = grants.primary_id
|
|
11111
11498
|
),
|
|
11112
11499
|
_sixb_scope_reached_links(
|
|
11113
11500
|
project_id,
|
|
@@ -11133,16 +11520,16 @@ function compileSelectedReadScopeCte(scopeJson, projectId) {
|
|
|
11133
11520
|
edge.target_id,
|
|
11134
11521
|
selection.property_ids
|
|
11135
11522
|
FROM _sixb_scope_reachable AS parent
|
|
11136
|
-
JOIN _sixb_scope_link_selections AS selection
|
|
11523
|
+
CROSS JOIN _sixb_scope_link_selections AS selection
|
|
11137
11524
|
ON selection.parent_node_id = parent.node_id
|
|
11138
11525
|
AND selection.source_object_type_id = parent.object_type_id
|
|
11139
|
-
JOIN links AS edge
|
|
11526
|
+
CROSS JOIN links AS edge
|
|
11140
11527
|
ON edge.project_id = parent.project_id
|
|
11141
11528
|
AND edge.source_type_id = parent.object_type_id
|
|
11142
11529
|
AND edge.source_id = parent.primary_id
|
|
11143
11530
|
AND edge.link_id = selection.link_id
|
|
11144
11531
|
AND edge.target_type_id = selection.target_object_type_id
|
|
11145
|
-
JOIN objects AS target
|
|
11532
|
+
CROSS JOIN objects AS target
|
|
11146
11533
|
ON target.project_id = edge.project_id
|
|
11147
11534
|
AND target.object_type_id = edge.target_type_id
|
|
11148
11535
|
AND target.primary_id = edge.target_id
|
|
@@ -11314,6 +11701,7 @@ var SQLITE_OBJECT_QUERY_CAPABILITIES = {
|
|
|
11314
11701
|
refs: true,
|
|
11315
11702
|
filter: true,
|
|
11316
11703
|
text: true,
|
|
11704
|
+
vector: true,
|
|
11317
11705
|
sort: true,
|
|
11318
11706
|
limit: true,
|
|
11319
11707
|
page: true,
|
|
@@ -11366,7 +11754,7 @@ var SQLITE_OBJECT_QUERY_CAPABILITIES = {
|
|
|
11366
11754
|
"SQLite object query pushdown supports start/refs/filter/text/sort/limit/page/traverse/set/project/expand over JSON properties and object links.",
|
|
11367
11755
|
"expand hydrates linked objects in-database (top-N per parent via row_number() + json_group_array); core resolves each expansion's cardinality before pushdown, and a mixed/unresolved one stays on the fallback.",
|
|
11368
11756
|
"Ordered decimal predicates and sorting use the bounded core fallback because SQLite has no native exact decimal type; canonical decimal equality remains pushdown-safe.",
|
|
11369
|
-
"Relevance sorting
|
|
11757
|
+
"Relevance sorting and unresolved start.includeSubtypes remain planner fallback or rejection cases."
|
|
11370
11758
|
]
|
|
11371
11759
|
};
|
|
11372
11760
|
|
|
@@ -11389,15 +11777,23 @@ class SqliteObjectStorage {
|
|
|
11389
11777
|
return createSqliteSelectedReader(this.db, params, () => this.queryCapabilities());
|
|
11390
11778
|
}
|
|
11391
11779
|
async queryObjects(params) {
|
|
11780
|
+
if (hasVectorProfile3(params.query))
|
|
11781
|
+
return runDeferredReadTransaction(this.db, () => this.reader.queryObjects(params));
|
|
11392
11782
|
return this.reader.queryObjects(params);
|
|
11393
11783
|
}
|
|
11394
11784
|
async countObjects(params) {
|
|
11785
|
+
if (hasVectorProfile3(params.query))
|
|
11786
|
+
return runDeferredReadTransaction(this.db, () => this.reader.countObjects(params));
|
|
11395
11787
|
return this.reader.countObjects(params);
|
|
11396
11788
|
}
|
|
11397
11789
|
async existsObjects(params) {
|
|
11790
|
+
if (hasVectorProfile3(params.query))
|
|
11791
|
+
return runDeferredReadTransaction(this.db, () => this.reader.existsObjects(params));
|
|
11398
11792
|
return this.reader.existsObjects(params);
|
|
11399
11793
|
}
|
|
11400
11794
|
async facetObjects(params) {
|
|
11795
|
+
if (hasVectorProfile3(params.query))
|
|
11796
|
+
return runDeferredReadTransaction(this.db, () => this.reader.facetObjects(params));
|
|
11401
11797
|
return this.reader.facetObjects(params);
|
|
11402
11798
|
}
|
|
11403
11799
|
async getByPrimaryId(params) {
|
|
@@ -11689,6 +12085,7 @@ import {
|
|
|
11689
12085
|
linkRefSortKey,
|
|
11690
12086
|
linkScopeSortKey as linkScopeSortKey2,
|
|
11691
12087
|
MaterializationConflictError as MaterializationConflictError6,
|
|
12088
|
+
MaterializationValidationError as MaterializationValidationError2,
|
|
11692
12089
|
objectRefKey as objectRefKey3,
|
|
11693
12090
|
objectRefSortKey,
|
|
11694
12091
|
telemetryPointKey as telemetryPointKey2,
|
|
@@ -13176,6 +13573,12 @@ class SqliteOntologyMaterializationStorage {
|
|
|
13176
13573
|
this.sessions = new SqliteMaterializationSessions(db, context);
|
|
13177
13574
|
this.writer = new SqliteMaterializationWriter(db);
|
|
13178
13575
|
}
|
|
13576
|
+
assertVectorSession(session, projectId, commitId) {
|
|
13577
|
+
const active = this.sessions.require(session);
|
|
13578
|
+
if (active.header.commit.projectId !== projectId || commitId !== undefined && active.header.commit.id !== commitId) {
|
|
13579
|
+
throw new MaterializationValidationError2("Vector mutation does not belong to this materialization session.");
|
|
13580
|
+
}
|
|
13581
|
+
}
|
|
13179
13582
|
async begin(input) {
|
|
13180
13583
|
assertMaterializationHeader(input);
|
|
13181
13584
|
const session = this.sessions.create(input);
|
|
@@ -13613,7 +14016,7 @@ class SqliteOntologyMaterializationStorage {
|
|
|
13613
14016
|
import { serializeSixbFailure as serializeSixbFailure2 } from "@sixb/core/internal/errors";
|
|
13614
14017
|
import {
|
|
13615
14018
|
MaterializationConflictError as MaterializationConflictError7,
|
|
13616
|
-
MaterializationValidationError as
|
|
14019
|
+
MaterializationValidationError as MaterializationValidationError3
|
|
13617
14020
|
} from "@sixb/core/internal/materialization";
|
|
13618
14021
|
import { ONTOLOGY_OUTBOX_FAILURE_CODES as ONTOLOGY_OUTBOX_FAILURE_CODES2 } from "@sixb/core/storage";
|
|
13619
14022
|
class SqliteOntologyOutboxStorage {
|
|
@@ -13631,7 +14034,7 @@ class SqliteOntologyOutboxStorage {
|
|
|
13631
14034
|
const leaseExpiry = assertTimestamp(input.leaseExpiresAt, "Ontology outbox lease expiry");
|
|
13632
14035
|
assertNonblank(input.leaseId, "Ontology outbox lease id");
|
|
13633
14036
|
if (leaseExpiry <= now) {
|
|
13634
|
-
throw new
|
|
14037
|
+
throw new MaterializationValidationError3("Ontology outbox lease expiry must be later than the claim time.");
|
|
13635
14038
|
}
|
|
13636
14039
|
const eligible = this.db.query(`SELECT CAST(rowid AS TEXT) AS rowId
|
|
13637
14040
|
FROM ontology_outbox INDEXED BY idx_ontology_outbox_claim
|
|
@@ -13756,7 +14159,7 @@ function validateLeaseIds(ids) {
|
|
|
13756
14159
|
for (const id of ids) {
|
|
13757
14160
|
assertNonblank(id, "Ontology outbox event id");
|
|
13758
14161
|
if (seen.has(id)) {
|
|
13759
|
-
throw new
|
|
14162
|
+
throw new MaterializationValidationError3(`Ontology outbox lease batch repeats event '${id}'.`);
|
|
13760
14163
|
}
|
|
13761
14164
|
seen.add(id);
|
|
13762
14165
|
}
|
|
@@ -13771,7 +14174,7 @@ function leaseConflict() {
|
|
|
13771
14174
|
}
|
|
13772
14175
|
|
|
13773
14176
|
// src/ontology-storage/sources.ts
|
|
13774
|
-
import { MaterializationValidationError as
|
|
14177
|
+
import { MaterializationValidationError as MaterializationValidationError4 } from "@sixb/core/internal/materialization";
|
|
13775
14178
|
import {
|
|
13776
14179
|
assertSourceBeginInput as assertBeginInput,
|
|
13777
14180
|
assertSourceExecutionIdentity as assertExecutionIdentity,
|
|
@@ -13911,7 +14314,7 @@ class SqliteOntologySourceStorage {
|
|
|
13911
14314
|
throw sourceConflict(`Source materialization '${input.materializationId}' cannot transition from '${manifest.status}' to 'ready'.`);
|
|
13912
14315
|
}
|
|
13913
14316
|
if (input.readyAt < manifest.created_at) {
|
|
13914
|
-
throw new
|
|
14317
|
+
throw new MaterializationValidationError4("Source readyAt cannot precede source createdAt.");
|
|
13915
14318
|
}
|
|
13916
14319
|
this.assertReadyState(manifest, input.rootCount, input.assertionCount);
|
|
13917
14320
|
const result = this.db.query(`
|
|
@@ -13994,7 +14397,7 @@ class SqliteOntologySourceStorage {
|
|
|
13994
14397
|
}
|
|
13995
14398
|
transitionToAbandoned(manifest, abandonedAt) {
|
|
13996
14399
|
if (abandonedAt < manifest.created_at || manifest.ready_at !== null && abandonedAt < manifest.ready_at) {
|
|
13997
|
-
throw new
|
|
14400
|
+
throw new MaterializationValidationError4("Source abandonedAt cannot precede source creation or readiness.");
|
|
13998
14401
|
}
|
|
13999
14402
|
const changed = this.db.query(`
|
|
14000
14403
|
UPDATE ontology_sources
|
|
@@ -14019,7 +14422,7 @@ class SqliteOntologySourceStorage {
|
|
|
14019
14422
|
WHERE project_id = ? AND source_id = ? AND materialization_id = ?
|
|
14020
14423
|
`).get(manifest.project_id, manifest.source_id, manifest.materialization_id, manifest.project_id, manifest.source_id, manifest.materialization_id);
|
|
14021
14424
|
if (counts.assertions !== assertionCount || counts.roots !== rootCount || counts.ordinals !== rootCount || rootCount > 0 && (counts.min_ordinal !== 0 || counts.max_ordinal !== rootCount - 1)) {
|
|
14022
|
-
throw new
|
|
14425
|
+
throw new MaterializationValidationError4("Source ready counts do not match the staged roots and assertions.");
|
|
14023
14426
|
}
|
|
14024
14427
|
assertSourceRootCoverage(this.db, manifest);
|
|
14025
14428
|
const invalid = this.db.query(manifest.projection_kind === "link" ? `
|
|
@@ -14047,7 +14450,7 @@ class SqliteOntologySourceStorage {
|
|
|
14047
14450
|
LIMIT 1
|
|
14048
14451
|
`).get(manifest.project_id, manifest.source_id, manifest.materialization_id);
|
|
14049
14452
|
if (invalid) {
|
|
14050
|
-
throw new
|
|
14453
|
+
throw new MaterializationValidationError4(manifest.projection_kind === "link" ? "Link projection roots must contain exactly their matching link assertion." : "Object projection roots must contain exactly their matching object assertion plus links sourced from that root.");
|
|
14051
14454
|
}
|
|
14052
14455
|
}
|
|
14053
14456
|
findStageRows(input, rows) {
|
|
@@ -14153,16 +14556,228 @@ class SqliteOntologySourceStorage {
|
|
|
14153
14556
|
}
|
|
14154
14557
|
}
|
|
14155
14558
|
|
|
14559
|
+
// src/ontology-storage/vector-indexing.ts
|
|
14560
|
+
import { parseSixbFailure as parseSixbFailure3 } from "@sixb/core/internal/errors";
|
|
14561
|
+
import {
|
|
14562
|
+
VECTOR_INDEXING_FAILURE_CODES
|
|
14563
|
+
} from "@sixb/core/storage";
|
|
14564
|
+
|
|
14565
|
+
class SqliteVectorIndexingStorage {
|
|
14566
|
+
db;
|
|
14567
|
+
run;
|
|
14568
|
+
assertSession;
|
|
14569
|
+
constructor(db, run, assertSession) {
|
|
14570
|
+
this.db = db;
|
|
14571
|
+
this.run = run;
|
|
14572
|
+
this.assertSession = assertSession;
|
|
14573
|
+
}
|
|
14574
|
+
async schedule(input) {
|
|
14575
|
+
this.assertSession(input.session, input.projectId);
|
|
14576
|
+
for (const ref of input.deleted)
|
|
14577
|
+
this.db.query(`DELETE FROM object_vector_indexing WHERE project_id = ? AND object_type_id = ? AND primary_id = ?`).run(input.projectId, ref.objectTypeId, ref.primaryId);
|
|
14578
|
+
const insert = this.db.query(`INSERT INTO object_vector_indexing (project_id, id, object_type_id, primary_id, profile, batch_id, request, status, available_at, dispatch_at)
|
|
14579
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, 'pending', ?, ?)
|
|
14580
|
+
ON CONFLICT (project_id, object_type_id, primary_id, profile) DO UPDATE SET id = excluded.id, batch_id = excluded.batch_id, request = excluded.request, status = 'pending', available_at = excluded.available_at, dispatch_at = excluded.dispatch_at, values_json = NULL, error = NULL`);
|
|
14581
|
+
for (const { batchId, ...request } of input.requests)
|
|
14582
|
+
insert.run(input.projectId, request.id, request.ref.objectTypeId, request.ref.primaryId, request.profile, batchId ?? null, JSON.stringify(request), input.availableAt, input.availableAt);
|
|
14583
|
+
}
|
|
14584
|
+
async complete(input) {
|
|
14585
|
+
this.assertSession(input.session, input.projectId);
|
|
14586
|
+
const remove = this.db.query(`DELETE FROM object_vector_indexing WHERE project_id = ? AND object_type_id = ? AND primary_id = ? AND profile = ? AND json_extract(request, '$.configuration') = ? AND json_extract(request, '$.sourceFingerprint') = ?`);
|
|
14587
|
+
for (const entry of input.entries) {
|
|
14588
|
+
remove.run(input.projectId, entry.ref.objectTypeId, entry.ref.primaryId, entry.profile, entry.configuration, entry.sourceFingerprint);
|
|
14589
|
+
}
|
|
14590
|
+
}
|
|
14591
|
+
async dispatched(input) {
|
|
14592
|
+
await this.run(() => {
|
|
14593
|
+
const update = this.db.query(`UPDATE object_vector_indexing SET dispatch_at = ? WHERE project_id = ? AND id = ?`);
|
|
14594
|
+
for (const id of input.ids)
|
|
14595
|
+
update.run(input.nextDispatchAt, input.projectId, id);
|
|
14596
|
+
});
|
|
14597
|
+
}
|
|
14598
|
+
async get(input) {
|
|
14599
|
+
return this.run(() => {
|
|
14600
|
+
const row = this.db.query(`SELECT batch_id, request, status, available_at, values_json, error FROM object_vector_indexing WHERE project_id = ? AND id = ?`).get(input.projectId, input.id);
|
|
14601
|
+
return row ? decode(row) : null;
|
|
14602
|
+
});
|
|
14603
|
+
}
|
|
14604
|
+
async getBatch(input) {
|
|
14605
|
+
return this.run(() => this.db.query(`
|
|
14606
|
+
SELECT batch_id, request, status, available_at, values_json, error FROM object_vector_indexing
|
|
14607
|
+
WHERE project_id = ? AND batch_id = ? ORDER BY id`).all(input.projectId, input.batchId).map(decode));
|
|
14608
|
+
}
|
|
14609
|
+
async getBatchMember(input) {
|
|
14610
|
+
return this.run(() => {
|
|
14611
|
+
const row = this.db.query(`
|
|
14612
|
+
SELECT batch_id, request, status, available_at, values_json, error
|
|
14613
|
+
FROM object_vector_indexing WHERE project_id = ? AND object_type_id = ?
|
|
14614
|
+
AND primary_id = ? AND profile = ? AND batch_id = ?`).get(input.projectId, input.ref.objectTypeId, input.ref.primaryId, input.profile, input.batchId);
|
|
14615
|
+
return row ? decode(row) : null;
|
|
14616
|
+
});
|
|
14617
|
+
}
|
|
14618
|
+
async updateBatch(input) {
|
|
14619
|
+
return this.run(() => this.db.transaction(() => {
|
|
14620
|
+
const status = this.db.query("SELECT status FROM object_vector_indexing WHERE project_id = ? AND id = ?");
|
|
14621
|
+
if (input.requireAll && input.updates.some((update) => status.get(input.projectId, update.id)?.status !== update.expectedStatus))
|
|
14622
|
+
return false;
|
|
14623
|
+
const updateRow = this.db.query(`UPDATE object_vector_indexing
|
|
14624
|
+
SET status = ?, available_at = ?, values_json = COALESCE(?, values_json), error = ?
|
|
14625
|
+
WHERE project_id = ? AND id = ? AND status = ?`);
|
|
14626
|
+
for (const update of input.updates)
|
|
14627
|
+
updateRow.run(update.status, update.availableAt, update.values ? JSON.stringify(update.values) : null, update.error ? JSON.stringify(update.error) : null, input.projectId, update.id, update.expectedStatus);
|
|
14628
|
+
return true;
|
|
14629
|
+
})());
|
|
14630
|
+
}
|
|
14631
|
+
async listDue(input) {
|
|
14632
|
+
return this.run(() => this.db.query(`SELECT batch_id, request, status, available_at, NULL AS values_json, error FROM object_vector_indexing WHERE project_id = ? AND status <> 'failed' AND dispatch_at <= ? ORDER BY dispatch_at, id LIMIT ?`).all(input.projectId, input.now, input.limit).map(decode));
|
|
14633
|
+
}
|
|
14634
|
+
async update(input) {
|
|
14635
|
+
return this.run(() => this.db.query(`UPDATE object_vector_indexing SET status = ?, available_at = ?, values_json = COALESCE(?, values_json), error = ? WHERE project_id = ? AND id = ? AND status = ?`).run(input.status, input.availableAt, input.values ? JSON.stringify(input.values) : null, input.error ? JSON.stringify(input.error) : null, input.projectId, input.id, input.expectedStatus).changes === 1);
|
|
14636
|
+
}
|
|
14637
|
+
async remove(input) {
|
|
14638
|
+
await this.run(() => {
|
|
14639
|
+
this.db.query(`DELETE FROM object_vector_indexing WHERE project_id = ? AND id = ?`).run(input.projectId, input.id);
|
|
14640
|
+
});
|
|
14641
|
+
}
|
|
14642
|
+
}
|
|
14643
|
+
function decode(row) {
|
|
14644
|
+
const request = JSON.parse(row.request);
|
|
14645
|
+
return {
|
|
14646
|
+
...request,
|
|
14647
|
+
...row.batch_id ? { batchId: row.batch_id } : {},
|
|
14648
|
+
status: row.status,
|
|
14649
|
+
availableAt: row.available_at,
|
|
14650
|
+
...row.values_json ? { values: JSON.parse(row.values_json) } : {},
|
|
14651
|
+
...row.error ? {
|
|
14652
|
+
error: parseSixbFailure3(row.error, VECTOR_INDEXING_FAILURE_CODES)
|
|
14653
|
+
} : {}
|
|
14654
|
+
};
|
|
14655
|
+
}
|
|
14656
|
+
|
|
14657
|
+
// src/ontology-storage/vectors.ts
|
|
14658
|
+
import { MaterializationConflictError as MaterializationConflictError8 } from "@sixb/core/internal/materialization";
|
|
14659
|
+
class SqliteOntologyVectorStorage {
|
|
14660
|
+
db;
|
|
14661
|
+
runRootOperation;
|
|
14662
|
+
assertSession;
|
|
14663
|
+
constructor(db, runRootOperation, assertSession) {
|
|
14664
|
+
this.db = db;
|
|
14665
|
+
this.runRootOperation = runRootOperation;
|
|
14666
|
+
this.assertSession = assertSession;
|
|
14667
|
+
}
|
|
14668
|
+
async list(input) {
|
|
14669
|
+
return this.runRootOperation(() => {
|
|
14670
|
+
const rows = this.db.query(`
|
|
14671
|
+
SELECT profile, configuration, source, source_fingerprint, last_commit_id
|
|
14672
|
+
FROM object_vectors
|
|
14673
|
+
WHERE project_id = ? AND object_type_id = ? AND primary_id = ?
|
|
14674
|
+
ORDER BY profile
|
|
14675
|
+
`).all(input.projectId, input.ref.objectTypeId, input.ref.primaryId);
|
|
14676
|
+
return rows.map((row) => ({
|
|
14677
|
+
ref: { ...input.ref },
|
|
14678
|
+
profile: row.profile,
|
|
14679
|
+
configuration: row.configuration,
|
|
14680
|
+
source: JSON.parse(row.source),
|
|
14681
|
+
sourceFingerprint: row.source_fingerprint,
|
|
14682
|
+
lastCommitId: row.last_commit_id
|
|
14683
|
+
}));
|
|
14684
|
+
});
|
|
14685
|
+
}
|
|
14686
|
+
async listBatch(input) {
|
|
14687
|
+
if (!input.refs.length)
|
|
14688
|
+
return [];
|
|
14689
|
+
return this.runRootOperation(() => {
|
|
14690
|
+
const rows = this.db.query(`
|
|
14691
|
+
WITH requested AS (
|
|
14692
|
+
SELECT DISTINCT json_extract(value, '$.objectTypeId') AS object_type_id,
|
|
14693
|
+
json_extract(value, '$.primaryId') AS primary_id FROM json_each(?)
|
|
14694
|
+
)
|
|
14695
|
+
SELECT stored.object_type_id, stored.primary_id, stored.profile, stored.configuration,
|
|
14696
|
+
stored.source, stored.source_fingerprint, stored.last_commit_id
|
|
14697
|
+
FROM requested CROSS JOIN object_vectors AS stored
|
|
14698
|
+
WHERE stored.project_id = ? AND stored.object_type_id = requested.object_type_id
|
|
14699
|
+
AND stored.primary_id = requested.primary_id
|
|
14700
|
+
ORDER BY stored.object_type_id, stored.primary_id, stored.profile
|
|
14701
|
+
`).all(JSON.stringify(input.refs), input.projectId);
|
|
14702
|
+
return rows.map((row) => ({
|
|
14703
|
+
ref: { objectTypeId: row.object_type_id, primaryId: row.primary_id },
|
|
14704
|
+
profile: row.profile,
|
|
14705
|
+
configuration: row.configuration,
|
|
14706
|
+
source: JSON.parse(row.source),
|
|
14707
|
+
sourceFingerprint: row.source_fingerprint,
|
|
14708
|
+
lastCommitId: row.last_commit_id
|
|
14709
|
+
}));
|
|
14710
|
+
});
|
|
14711
|
+
}
|
|
14712
|
+
async removeBatch(input) {
|
|
14713
|
+
this.assertSession(input.session, input.projectId);
|
|
14714
|
+
if (!input.entries.length)
|
|
14715
|
+
return;
|
|
14716
|
+
const { changes } = this.db.query(`
|
|
14717
|
+
DELETE FROM object_vectors WHERE rowid IN (
|
|
14718
|
+
SELECT stored.rowid FROM json_each(?) AS requested CROSS JOIN object_vectors AS stored
|
|
14719
|
+
WHERE stored.project_id = ? AND stored.object_type_id = json_extract(requested.value, '$.ref.objectTypeId')
|
|
14720
|
+
AND stored.primary_id = json_extract(requested.value, '$.ref.primaryId')
|
|
14721
|
+
AND stored.profile = json_extract(requested.value, '$.profile')
|
|
14722
|
+
AND stored.last_commit_id = json_extract(requested.value, '$.expectedCommitId')
|
|
14723
|
+
)
|
|
14724
|
+
`).run(JSON.stringify(input.entries), input.projectId);
|
|
14725
|
+
if (changes !== input.entries.length)
|
|
14726
|
+
throw vectorConflict();
|
|
14727
|
+
}
|
|
14728
|
+
async write(input) {
|
|
14729
|
+
const { value } = input;
|
|
14730
|
+
this.assertSession(input.session, input.projectId, value.lastCommitId);
|
|
14731
|
+
const embedding = encodeSqliteVector(value.values);
|
|
14732
|
+
const changes = input.expectedCommitId === null ? this.db.query(`
|
|
14733
|
+
INSERT INTO object_vectors (
|
|
14734
|
+
project_id, object_type_id, primary_id, profile,
|
|
14735
|
+
configuration, source, source_fingerprint, embedding, last_commit_id
|
|
14736
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
14737
|
+
ON CONFLICT (project_id, object_type_id, primary_id, profile) DO NOTHING
|
|
14738
|
+
`).run(input.projectId, value.ref.objectTypeId, value.ref.primaryId, value.profile, value.configuration, JSON.stringify(value.source), value.sourceFingerprint, embedding, value.lastCommitId).changes : this.db.query(`
|
|
14739
|
+
UPDATE object_vectors
|
|
14740
|
+
SET configuration = ?, source = ?, source_fingerprint = ?, embedding = ?, last_commit_id = ?
|
|
14741
|
+
WHERE project_id = ? AND object_type_id = ? AND primary_id = ?
|
|
14742
|
+
AND profile = ? AND last_commit_id = ?
|
|
14743
|
+
`).run(value.configuration, JSON.stringify(value.source), value.sourceFingerprint, embedding, value.lastCommitId, input.projectId, value.ref.objectTypeId, value.ref.primaryId, value.profile, input.expectedCommitId).changes;
|
|
14744
|
+
if (changes !== 1)
|
|
14745
|
+
throw vectorConflict();
|
|
14746
|
+
}
|
|
14747
|
+
async writeBatch(input) {
|
|
14748
|
+
for (const entry of input.entries) {
|
|
14749
|
+
await this.write({ session: input.session, projectId: input.projectId, ...entry });
|
|
14750
|
+
}
|
|
14751
|
+
}
|
|
14752
|
+
async remove(input) {
|
|
14753
|
+
this.assertSession(input.session, input.projectId);
|
|
14754
|
+
const { changes } = this.db.query(`
|
|
14755
|
+
DELETE FROM object_vectors
|
|
14756
|
+
WHERE project_id = ? AND object_type_id = ? AND primary_id = ?
|
|
14757
|
+
AND profile = ? AND last_commit_id = ?
|
|
14758
|
+
`).run(input.projectId, input.ref.objectTypeId, input.ref.primaryId, input.profile, input.expectedCommitId);
|
|
14759
|
+
if (changes !== 1)
|
|
14760
|
+
throw vectorConflict();
|
|
14761
|
+
}
|
|
14762
|
+
}
|
|
14763
|
+
function vectorConflict() {
|
|
14764
|
+
return new MaterializationConflictError8("effective-state", "Vector changed since it was prepared.");
|
|
14765
|
+
}
|
|
14766
|
+
|
|
14156
14767
|
// src/ontology-storage/index.ts
|
|
14157
14768
|
class SqliteOntologyStorage {
|
|
14158
14769
|
commits;
|
|
14159
14770
|
sources;
|
|
14160
14771
|
materializations;
|
|
14772
|
+
vectorIndexing;
|
|
14773
|
+
vectors;
|
|
14161
14774
|
outbox;
|
|
14162
14775
|
constructor(input) {
|
|
14163
14776
|
this.commits = new SqliteOntologyCommitStorage(input.db, input.runRootOperation);
|
|
14164
14777
|
this.sources = new SqliteOntologySourceStorage(input.db, input.runRootOperation);
|
|
14165
14778
|
this.materializations = new SqliteOntologyMaterializationStorage(input.db, input.transactionContext);
|
|
14779
|
+
this.vectorIndexing = new SqliteVectorIndexingStorage(input.db, input.runRootOperation, (session, projectId) => this.materializations.assertVectorSession(session, projectId));
|
|
14780
|
+
this.vectors = new SqliteOntologyVectorStorage(input.db, input.runRootOperation, (session, projectId, commitId) => this.materializations.assertVectorSession(session, projectId, commitId));
|
|
14166
14781
|
this.outbox = new SqliteOntologyOutboxStorage(input.db, input.runRootOperation);
|
|
14167
14782
|
}
|
|
14168
14783
|
deactivateSessions() {
|
|
@@ -14171,7 +14786,7 @@ class SqliteOntologyStorage {
|
|
|
14171
14786
|
}
|
|
14172
14787
|
|
|
14173
14788
|
// src/pipeline-run-storage.ts
|
|
14174
|
-
import { parseSixbFailure as
|
|
14789
|
+
import { parseSixbFailure as parseSixbFailure4, serializeSixbFailure as serializeSixbFailure3 } from "@sixb/core/internal/errors";
|
|
14175
14790
|
import { assertPipelineRunExecution } from "@sixb/core/internal/pipeline-run-storage-provider";
|
|
14176
14791
|
import { canRequeuePipelineRunAfterEnqueueFailure } from "@sixb/core/internal/storage";
|
|
14177
14792
|
import { PIPELINE_RUN_FAILURE_CODES, PipelineRunError } from "@sixb/core/storage";
|
|
@@ -14493,7 +15108,7 @@ function rowToPipelineRunRecord(row) {
|
|
|
14493
15108
|
datasetId: row.output_dataset_id,
|
|
14494
15109
|
versionId: row.output_version_id
|
|
14495
15110
|
} : undefined,
|
|
14496
|
-
error: row.error === null ? undefined :
|
|
15111
|
+
error: row.error === null ? undefined : parseSixbFailure4(row.error, PIPELINE_RUN_FAILURE_CODES)
|
|
14497
15112
|
};
|
|
14498
15113
|
}
|
|
14499
15114
|
function rowToPipelineStepRunRecord(row) {
|
|
@@ -14514,7 +15129,7 @@ function rowToPipelineStepRunRecord(row) {
|
|
|
14514
15129
|
versionId: row.output_version_id
|
|
14515
15130
|
} : undefined,
|
|
14516
15131
|
rowsWritten: row.rows_written ?? undefined,
|
|
14517
|
-
error: row.error === null ? undefined :
|
|
15132
|
+
error: row.error === null ? undefined : parseSixbFailure4(row.error, PIPELINE_RUN_FAILURE_CODES)
|
|
14518
15133
|
};
|
|
14519
15134
|
}
|
|
14520
15135
|
function assertOptionalNonNegativeInteger(value, fieldName) {
|
|
@@ -15459,7 +16074,7 @@ function invalidRecord2(message) {
|
|
|
15459
16074
|
}
|
|
15460
16075
|
|
|
15461
16076
|
// src/sync-run-storage.ts
|
|
15462
|
-
import { parseSixbFailure as
|
|
16077
|
+
import { parseSixbFailure as parseSixbFailure5, serializeSixbFailure as serializeSixbFailure5 } from "@sixb/core/internal/errors";
|
|
15463
16078
|
import { canRequeueSyncRunAfterEnqueueFailure } from "@sixb/core/internal/storage";
|
|
15464
16079
|
import { assertSyncRunExecution } from "@sixb/core/internal/sync-run-storage-provider";
|
|
15465
16080
|
import { SYNC_RUN_FAILURE_CODES, SyncRunError } from "@sixb/core/storage";
|
|
@@ -15662,7 +16277,7 @@ function rowToSyncRunRecord(row) {
|
|
|
15662
16277
|
} : undefined,
|
|
15663
16278
|
expectedLatestVersionId: row.expected_latest_version_id ?? undefined,
|
|
15664
16279
|
commitMessage: row.commit_message ?? undefined,
|
|
15665
|
-
error: row.error === null ? undefined :
|
|
16280
|
+
error: row.error === null ? undefined : parseSixbFailure5(row.error, SYNC_RUN_FAILURE_CODES),
|
|
15666
16281
|
checkpoint: parseCheckpoint(row.checkpoint)
|
|
15667
16282
|
};
|
|
15668
16283
|
}
|
|
@@ -15803,7 +16418,7 @@ class SqliteTimeseriesStorage {
|
|
|
15803
16418
|
}
|
|
15804
16419
|
|
|
15805
16420
|
// src/webhook-run-storage.ts
|
|
15806
|
-
import { parseSixbFailure as
|
|
16421
|
+
import { parseSixbFailure as parseSixbFailure6, serializeSixbFailure as serializeSixbFailure6 } from "@sixb/core/internal/errors";
|
|
15807
16422
|
import { assertWebhookRunExecution } from "@sixb/core/internal/webhook-run-storage-provider";
|
|
15808
16423
|
import { canRetryWebhookRun, WEBHOOK_RUN_FAILURE_CODES, WebhookRunError } from "@sixb/core/storage";
|
|
15809
16424
|
class SqliteWebhookRunStorage {
|
|
@@ -15949,7 +16564,7 @@ function rowToWebhookRunRecord(row) {
|
|
|
15949
16564
|
requestBodySha256: row.request_body_sha256,
|
|
15950
16565
|
responseStatus: row.response_status ?? undefined,
|
|
15951
16566
|
idempotencyKey: row.idempotency_key ?? undefined,
|
|
15952
|
-
error: row.error === null ? undefined :
|
|
16567
|
+
error: row.error === null ? undefined : parseSixbFailure6(row.error, WEBHOOK_RUN_FAILURE_CODES)
|
|
15953
16568
|
};
|
|
15954
16569
|
}
|
|
15955
16570
|
|
|
@@ -16178,7 +16793,7 @@ function assertNonNegativeInteger(value, fieldName) {
|
|
|
16178
16793
|
}
|
|
16179
16794
|
|
|
16180
16795
|
// src/workflow-run-storage.ts
|
|
16181
|
-
import { parseSixbFailure as
|
|
16796
|
+
import { parseSixbFailure as parseSixbFailure7, serializeSixbFailure as serializeSixbFailure7 } from "@sixb/core/internal/errors";
|
|
16182
16797
|
import {
|
|
16183
16798
|
assertWorkflowAgentNodeRunExecution,
|
|
16184
16799
|
assertWorkflowRunExecution
|
|
@@ -16736,7 +17351,7 @@ function rowToWorkflowRunRecord(row) {
|
|
|
16736
17351
|
queuedAt: row.queued_at ? new Date(row.queued_at) : undefined,
|
|
16737
17352
|
startedAt: new Date(row.started_at),
|
|
16738
17353
|
finishedAt: row.finished_at ? new Date(row.finished_at) : undefined,
|
|
16739
|
-
error: row.error === null ? undefined :
|
|
17354
|
+
error: row.error === null ? undefined : parseSixbFailure7(row.error, WORKFLOW_RUN_FAILURE_CODES),
|
|
16740
17355
|
attempt: row.attempt,
|
|
16741
17356
|
...row.execution_token && row.execution_queue_lease_expires_at ? {
|
|
16742
17357
|
execution: {
|
|
@@ -16761,7 +17376,7 @@ function rowToWorkflowNodeRunRecord(row) {
|
|
|
16761
17376
|
startedAt: new Date(row.started_at),
|
|
16762
17377
|
finishedAt: row.finished_at ? new Date(row.finished_at) : undefined,
|
|
16763
17378
|
output: row.output ? parseRecord2(row.output) : undefined,
|
|
16764
|
-
error: row.error === null ? undefined :
|
|
17379
|
+
error: row.error === null ? undefined : parseSixbFailure7(row.error, WORKFLOW_RUN_FAILURE_CODES)
|
|
16765
17380
|
};
|
|
16766
17381
|
}
|
|
16767
17382
|
function assertNonNegativeInteger2(value, fieldName) {
|
|
@@ -16789,7 +17404,7 @@ function rowToWorkflowAgentNodeRunRecord(row) {
|
|
|
16789
17404
|
...row.finish_reason ? { finishReason: row.finish_reason } : {},
|
|
16790
17405
|
...row.trace ? { trace: JSON.parse(row.trace) } : {},
|
|
16791
17406
|
...row.diagnostics ? { diagnostics: JSON.parse(row.diagnostics) } : {},
|
|
16792
|
-
...row.error ? { error:
|
|
17407
|
+
...row.error ? { error: parseSixbFailure7(row.error, AGENT_RUN_FAILURE_CODES3) } : {},
|
|
16793
17408
|
attempt: row.attempt,
|
|
16794
17409
|
...row.execution_token && row.execution_queue_lease_expires_at ? {
|
|
16795
17410
|
execution: {
|
|
@@ -17012,4 +17627,4 @@ export {
|
|
|
17012
17627
|
migrateSqliteStorage
|
|
17013
17628
|
};
|
|
17014
17629
|
|
|
17015
|
-
//# debugId=
|
|
17630
|
+
//# debugId=23F5EFFEE42C282464756E2164756E21
|