@segmentstream/ontology 0.143.0 → 0.144.0
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/CHANGELOG.md +12 -0
- package/dist/metric-routes.js +3 -2
- package/dist/migrate/apply.js +15 -8
- package/dist/replicated-entities.d.ts +14 -0
- package/dist/replicated-entities.js +20 -0
- package/dist/replication/baseline.js +2 -1
- package/dist/replication/legacy-baseline.js +2 -1
- package/dist/replication/model.d.ts +4 -1
- package/dist/replication/model.js +8 -4
- package/dist/replication/schema.js +2 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.144.0
|
|
4
|
+
|
|
5
|
+
The built-in entities `agent_chat`, `agent_review` and `app_feedback` replicate to the warehouse
|
|
6
|
+
as a workspace's own stored entities do: metric queries reach them as stored entities, such as a
|
|
7
|
+
visit metric grouped by its chat's `provider` through `rel.one(AgentChat, { on: { chat: "key" } })`,
|
|
8
|
+
and warehouse models can join them. The built-in `user` and `user_identity` stay in the ontology.
|
|
9
|
+
|
|
10
|
+
A migration applies what its release replicates even when the ontology did not change: when the
|
|
11
|
+
source's projection lacks an entity the release replicates, the migration installs its capture and
|
|
12
|
+
a scoped repair copies that entity's records alone. Existing workspaces start replicating these
|
|
13
|
+
entities at their next deployment.
|
|
14
|
+
|
|
3
15
|
## 0.143.0
|
|
4
16
|
|
|
5
17
|
Roles can grant the agent's web search: `agent_tool:web_search`. It gives a caller the agent's
|
package/dist/metric-routes.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { replicatesRecords } from "./replicated-entities.js";
|
|
1
2
|
import { User } from "./user.js";
|
|
2
3
|
/** A route follows at most this many to-one relationships. */
|
|
3
4
|
export const MAXIMUM_HOPS = 2;
|
|
@@ -114,9 +115,9 @@ class RouteCatalog {
|
|
|
114
115
|
modelMetric(name) {
|
|
115
116
|
return this.metrics.get(name) ?? refuse(unknownModelMetricMessage(name));
|
|
116
117
|
}
|
|
117
|
-
/** Declared properties, and the `id` of a
|
|
118
|
+
/** Declared properties, and the `id` of a replicated entity, which its replication view carries. */
|
|
118
119
|
hasProperty(entity, property) {
|
|
119
|
-
const stored = entity
|
|
120
|
+
const stored = replicatesRecords(entity);
|
|
120
121
|
return (entity.properties.some((candidate) => candidate.name === property) ||
|
|
121
122
|
(stored && property === "id"));
|
|
122
123
|
}
|
package/dist/migrate/apply.js
CHANGED
|
@@ -9,6 +9,7 @@ import { isNoopMigration, NO_RETAINED_STORAGE, RetainedStorage, retainedStorageJ
|
|
|
9
9
|
import { planMigration } from "./plan.js";
|
|
10
10
|
import { REPLICATION_DDL, REPLICATION_SCHEMA_VERSION, replicationEntityDdl, } from "../replication/schema.js";
|
|
11
11
|
import { lockReplicationLifecycle, lockReplicationSchema } from "../replication/transaction.js";
|
|
12
|
+
import { replicatesRecords } from "../replicated-entities.js";
|
|
12
13
|
import { prepareReplicationBaseline } from "../replication/baseline.js";
|
|
13
14
|
import { randomUUID } from "node:crypto";
|
|
14
15
|
import { recordWorkflowCatalog } from "../runtime/workflow-admission.js";
|
|
@@ -206,6 +207,14 @@ const runStep = (sql, step, stepIndex) => Effect.forEach(step.sql, (statement) =
|
|
|
206
207
|
const reconcileWorkflows = (plan, sql, workspaceId) => workspaceId === undefined
|
|
207
208
|
? Effect.void
|
|
208
209
|
: reconcileWorkflowUsers(principalsOntology(plan.target), { workspaceId }).pipe(Effect.provideService(SqlClient.SqlClient, sql));
|
|
210
|
+
/**
|
|
211
|
+
* Whether a source's recorded projection holds every entity this release replicates. One recorded
|
|
212
|
+
* before the release replicated an entity, such as a built-in entity, is not current: the
|
|
213
|
+
* migration installs its capture and copies it, though the ontology did not change.
|
|
214
|
+
*/
|
|
215
|
+
function replicatesAll(manifest, recorded) {
|
|
216
|
+
return resolveReplicationSelection(manifest).every((item) => recorded !== null && Object.hasOwn(recorded, item.entityId));
|
|
217
|
+
}
|
|
209
218
|
/**
|
|
210
219
|
* Applies a plan. Non-transactional steps run first, each statement on its own; they only add enum
|
|
211
220
|
* values and build indexes concurrently, and are safe to run again after a failure. Every other step
|
|
@@ -246,7 +255,8 @@ export const applyMigration = (plan, options) => Effect.gen(function* () {
|
|
|
246
255
|
const targetPresent = presence.targets && isNoopMigration(plan)
|
|
247
256
|
? "EXISTS (SELECT 1 FROM _ontology_replication_targets WHERE generation = active_generation)"
|
|
248
257
|
: "false";
|
|
249
|
-
const [state] = yield* sql.unsafe(`SELECT version, enabled, ${targetPresent} AS target_present
|
|
258
|
+
const [state] = yield* sql.unsafe(`SELECT version, enabled, ${targetPresent} AS target_present, selection
|
|
259
|
+
FROM _ontology_replication WHERE id`);
|
|
250
260
|
if (state?.enabled &&
|
|
251
261
|
state.version >= 6 &&
|
|
252
262
|
(yield* requestShadowSupersession(sql, plan.target.hash))) {
|
|
@@ -263,7 +273,7 @@ export const applyMigration = (plan, options) => Effect.gen(function* () {
|
|
|
263
273
|
}
|
|
264
274
|
if (isNoopMigration(plan) &&
|
|
265
275
|
state?.version === REPLICATION_SCHEMA_VERSION &&
|
|
266
|
-
(!state.enabled || state.target_present)) {
|
|
276
|
+
(!state.enabled || (state.target_present && replicatesAll(plan.target, state.selection)))) {
|
|
267
277
|
if (options.workspaceId !== undefined || syncsIdentities(plan)) {
|
|
268
278
|
// Under the migration lock, and only while the catalog still records this target.
|
|
269
279
|
yield* sql.withTransaction(Effect.gen(function* () {
|
|
@@ -340,11 +350,9 @@ export const applyMigration = (plan, options) => Effect.gen(function* () {
|
|
|
340
350
|
],
|
|
341
351
|
});
|
|
342
352
|
}
|
|
353
|
+
// A runtime-only upgrade adopts the projection this release replicates as well, such as
|
|
354
|
+
// the built-in entities it replicates; only a projection that changed is scanned again.
|
|
343
355
|
active = target;
|
|
344
|
-
// A runtime-only upgrade retains an existing explicit projection.
|
|
345
|
-
if (target?.manifest.hash === plan.target.hash) {
|
|
346
|
-
refresh = target.selection;
|
|
347
|
-
}
|
|
348
356
|
// Both writer protocols are fenced. Capture and schema changes commit on one stream.
|
|
349
357
|
yield* sql.unsafe("UPDATE _ontology_replication SET enabled = false WHERE id");
|
|
350
358
|
}
|
|
@@ -363,8 +371,7 @@ export const applyMigration = (plan, options) => Effect.gen(function* () {
|
|
|
363
371
|
}
|
|
364
372
|
if (plan.steps.some((step) => step.kind === "dropEntities")) {
|
|
365
373
|
for (const entity of previousManifest?.entities ?? []) {
|
|
366
|
-
if (
|
|
367
|
-
!entity.source &&
|
|
374
|
+
if (replicatesRecords(entity) &&
|
|
368
375
|
!plan.target.entities.some((item) => item.id === entity.id)) {
|
|
369
376
|
yield* retainReplicationHistory(sql, historyTableName(entity.name));
|
|
370
377
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EntityManifest } from "./manifest.js";
|
|
2
|
+
/**
|
|
3
|
+
* The built-in entities whose records replicate to the warehouse as the workspace's own stored
|
|
4
|
+
* entities do: the chats the agent is in, the replies held for review and the feedback members send
|
|
5
|
+
* the builders, which metrics and warehouse models join to the workspace's data. The user and their
|
|
6
|
+
* sign-in identities stay in the ontology: no metric route passes through the user
|
|
7
|
+
* (`metric-routes.ts`), and an identity is how a person signs in, nothing a query counts.
|
|
8
|
+
*/
|
|
9
|
+
export declare const REPLICATED_BUILT_IN_ENTITIES: ReadonlySet<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Whether an entity's records replicate: every stored entity the workspace declares, and the
|
|
12
|
+
* built-in entities above. A warehouse-backed entity is the warehouse's already.
|
|
13
|
+
*/
|
|
14
|
+
export declare function replicatesRecords(entity: Pick<EntityManifest, "name" | "builtIn" | "source">): boolean;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The built-in entities whose records replicate to the warehouse as the workspace's own stored
|
|
3
|
+
* entities do: the chats the agent is in, the replies held for review and the feedback members send
|
|
4
|
+
* the builders, which metrics and warehouse models join to the workspace's data. The user and their
|
|
5
|
+
* sign-in identities stay in the ontology: no metric route passes through the user
|
|
6
|
+
* (`metric-routes.ts`), and an identity is how a person signs in, nothing a query counts.
|
|
7
|
+
*/
|
|
8
|
+
export const REPLICATED_BUILT_IN_ENTITIES = new Set([
|
|
9
|
+
"agent_chat",
|
|
10
|
+
"agent_review",
|
|
11
|
+
"app_feedback",
|
|
12
|
+
]);
|
|
13
|
+
/**
|
|
14
|
+
* Whether an entity's records replicate: every stored entity the workspace declares, and the
|
|
15
|
+
* built-in entities above. A warehouse-backed entity is the warehouse's already.
|
|
16
|
+
*/
|
|
17
|
+
export function replicatesRecords(entity) {
|
|
18
|
+
return (entity.source === undefined &&
|
|
19
|
+
(!entity.builtIn || REPLICATED_BUILT_IN_ENTITIES.has(entity.name)));
|
|
20
|
+
}
|
|
@@ -6,6 +6,7 @@ import { REPLICATION_RECORD_BYTES, validateReplicationSelection, } from "./model
|
|
|
6
6
|
import { REPLICATION_TARGET_FILLS, REPLICATION_TARGET_METADATA, snapshotExpression, } from "./schema.js";
|
|
7
7
|
import { lockReplicationLifecycle, shareReplicationLifecycle } from "./transaction.js";
|
|
8
8
|
import { TARGET_MANIFEST_HASH, storedTargets } from "./stored-manifests.js";
|
|
9
|
+
import { replicatesRecords } from "../replicated-entities.js";
|
|
9
10
|
import { initialReplicationLineage } from "./lineage.js";
|
|
10
11
|
import { scheduleReplicationScans, replicationScanScopes, advanceReplicationScan, } from "./scans.js";
|
|
11
12
|
/** An initial scan cannot be created with the requested state or record projection. */
|
|
@@ -44,7 +45,7 @@ export const prepareReplicationBaseline = (sql, input) => sql.withTransaction(Ef
|
|
|
44
45
|
});
|
|
45
46
|
// Drain raw/pre-upgrade writers only at enablement; online pages never lock business tables.
|
|
46
47
|
const tables = input.manifest.entities
|
|
47
|
-
.filter(
|
|
48
|
+
.filter(replicatesRecords)
|
|
48
49
|
.flatMap((e) => [
|
|
49
50
|
tableName(e.name),
|
|
50
51
|
...e.relationships
|
|
@@ -4,6 +4,7 @@ import { joinColumnNames, joinTableName, quoteIdentifier as qi, quoteLiteral as
|
|
|
4
4
|
import { REPLICATION_RECORD_BYTES, validateReplicationSelection, } from "./model.js";
|
|
5
5
|
import { snapshotExpression } from "./schema.js";
|
|
6
6
|
import { createReplicationBaseline as createCurrentBaseline } from "./baseline.js";
|
|
7
|
+
import { replicatesRecords } from "../replicated-entities.js";
|
|
7
8
|
import { lockReplicationLifecycle } from "./transaction.js";
|
|
8
9
|
/** An initial snapshot cannot be created with the requested state or record projection. */
|
|
9
10
|
export class ReplicationBaselineFailed extends Schema.TaggedError()("ReplicationBaselineFailed", { message: Schema.String, cause: Schema.optionalKey(Schema.Unknown) }) {
|
|
@@ -35,7 +36,7 @@ export const createReplicationBaseline = (sql, input) => sql.withTransaction(Eff
|
|
|
35
36
|
});
|
|
36
37
|
// Drain older SDK transactions that started before the compatibility fence was enabled.
|
|
37
38
|
const tables = manifest.entities
|
|
38
|
-
.filter(
|
|
39
|
+
.filter(replicatesRecords)
|
|
39
40
|
.flatMap((e) => [
|
|
40
41
|
tableName(e.name),
|
|
41
42
|
...e.relationships
|
|
@@ -12,7 +12,10 @@ export interface ReplicationSelection {
|
|
|
12
12
|
export type ReplicationFills = Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
13
13
|
/** System fields and relationship keys always replicate. Only declared properties can opt out. */
|
|
14
14
|
export declare function replicatedFields(entity: EntityManifest): import("../query.js").QueryField[];
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Every stored entity the workspace declares, the built-in entities that replicate, and their
|
|
17
|
+
* relationships to one another replicate.
|
|
18
|
+
*/
|
|
16
19
|
export declare function resolveReplicationSelection(manifest: OntologyManifest): ReadonlyArray<ReplicationSelection>;
|
|
17
20
|
export interface ReplicationEvent {
|
|
18
21
|
readonly event_id: string;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { queryFields } from "../query.js";
|
|
3
|
+
import { replicatesRecords } from "../replicated-entities.js";
|
|
3
4
|
/** System fields and relationship keys always replicate. Only declared properties can opt out. */
|
|
4
5
|
export function replicatedFields(entity) {
|
|
5
6
|
const excluded = new Set(entity.properties.filter((p) => p.excludeFromReplication).map((p) => p.name));
|
|
6
7
|
return queryFields(entity).filter((field) => !excluded.has(field.name));
|
|
7
8
|
}
|
|
8
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* Every stored entity the workspace declares, the built-in entities that replicate, and their
|
|
11
|
+
* relationships to one another replicate.
|
|
12
|
+
*/
|
|
9
13
|
export function resolveReplicationSelection(manifest) {
|
|
10
|
-
const entities = manifest.entities.filter(
|
|
14
|
+
const entities = manifest.entities.filter(replicatesRecords);
|
|
11
15
|
const selection = entities.map((entity) => ({
|
|
12
16
|
entityId: entity.id,
|
|
13
17
|
fields: replicatedFields(entity).map((field) => field.name),
|
|
@@ -37,7 +41,7 @@ export function validateReplicationSelection(manifest, selection) {
|
|
|
37
41
|
};
|
|
38
42
|
for (const item of selection) {
|
|
39
43
|
const entity = manifest.entities.find((e) => e.id === item.entityId);
|
|
40
|
-
if (!entity || entity
|
|
44
|
+
if (!entity || !replicatesRecords(entity)) {
|
|
41
45
|
throw new Error(`Only stored business entities can be replicated: ${item.entityId}.`);
|
|
42
46
|
}
|
|
43
47
|
addView(entity.name);
|
|
@@ -50,7 +54,7 @@ export function validateReplicationSelection(manifest, selection) {
|
|
|
50
54
|
const target = manifest.entities.find((e) => e.name === relationship?.to);
|
|
51
55
|
if (relationship?.cardinality !== "many" ||
|
|
52
56
|
!target ||
|
|
53
|
-
target
|
|
57
|
+
!replicatesRecords(target) ||
|
|
54
58
|
!selection.some((s) => s.entityId === target.id)) {
|
|
55
59
|
throw new Error(`Replication of ${entity.name}.${name} requires both business entities.`);
|
|
56
60
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { columnName, historyTableName, quoteIdentifier as qi, quoteLiteral as ql, relationshipColumnName, SYSTEM_COLUMNS, tableName, joinTableName, } from "../migrate/storage.js";
|
|
3
|
+
import { replicatesRecords } from "../replicated-entities.js";
|
|
3
4
|
import { replicatedFields, REPLICATION_RECORD_BYTES } from "./model.js";
|
|
4
5
|
import { SHADOW_REPLICATION_DDL, SHADOW_CONTROL_JOBS_DDL, SHADOW_SOURCE_REPLACEMENTS_DDL, } from "./shadow-schema.js";
|
|
5
6
|
export const REPLICATION_SCHEMA_VERSION = 6;
|
|
@@ -138,9 +139,7 @@ export function snapshotExpression(entity, alias) {
|
|
|
138
139
|
}
|
|
139
140
|
/** History is the durable source. Triggers also reject old writers while capture is enabled. */
|
|
140
141
|
export function replicationEntityDdl(manifest, previous) {
|
|
141
|
-
return manifest.entities
|
|
142
|
-
.filter((e) => e.source === undefined && !e.builtIn)
|
|
143
|
-
.flatMap((entity) => {
|
|
142
|
+
return manifest.entities.filter(replicatesRecords).flatMap((entity) => {
|
|
144
143
|
const old = previous?.entities.find((item) => item.id === entity.id);
|
|
145
144
|
const compatible = {
|
|
146
145
|
...entity,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.144.0",
|
|
4
4
|
"description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|