@segmentstream/ontology 0.122.0 → 0.124.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 +53 -0
- package/README.md +25 -14
- package/dist/action.d.ts +11 -6
- package/dist/agent-chat.d.ts +30 -15
- package/dist/agent-chat.js +66 -2
- package/dist/analyze.d.ts +4 -0
- package/dist/analyze.js +63 -13
- package/dist/app-feedback.js +6 -5
- package/dist/chat.d.ts +10 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/manifest.d.ts +60 -7
- package/dist/manifest.js +37 -6
- package/dist/migrate/apply.js +5 -17
- package/dist/migrate/model.d.ts +24 -0
- package/dist/replication/baseline.d.ts +1 -2
- package/dist/replication/baseline.js +3 -2
- package/dist/replication/legacy-baseline.d.ts +1 -2
- package/dist/replication/legacy-baseline.js +3 -6
- package/dist/replication/migrate.d.ts +1 -10
- package/dist/replication/migrate.js +0 -37
- package/dist/replication/model.d.ts +6 -9
- package/dist/replication/model.js +13 -47
- package/dist/replication/schema.js +3 -0
- package/dist/replication/shadow.d.ts +7 -3
- package/dist/replication/shadow.js +9 -9
- package/dist/replication/store.d.ts +6 -2
- package/dist/replication/store.js +21 -46
- package/dist/runtime/agents.js +16 -6
- package/dist/runtime/generated-actions.js +5 -0
- package/dist/runtime/service-binding.d.ts +5 -1
- package/dist/runtime/service-binding.js +14 -5
- package/dist/service/agent/server.js +1 -0
- package/dist/service/chat/delivery.js +3 -0
- package/dist/service/mcp/server.js +5 -5
- package/dist/service/runtime-contract.d.ts +11 -1
- package/dist/service/schemas.d.ts +6 -0
- package/dist/storage/memory.d.ts +100 -0
- package/dist/storage/memory.js +281 -0
- package/dist/storage/sessions.d.ts +2 -2
- package/package.json +1 -1
package/dist/manifest.d.ts
CHANGED
|
@@ -91,7 +91,8 @@ import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } fro
|
|
|
91
91
|
* `channel:<name>`, its people's accounts.
|
|
92
92
|
* Within version 15, the top-level `inbox`, written only when declared, holds the wire names of the
|
|
93
93
|
* `roles` whose people's private chats the agent registers as `agent_chat` records of kind
|
|
94
|
-
* `private
|
|
94
|
+
* `private`, and in `takeover.channels` the channels whose chats staff may take over from the
|
|
95
|
+
* agent. Older readers ignore it, register none and let none be taken over.
|
|
95
96
|
*/
|
|
96
97
|
export declare const MANIFEST_VERSION = 15;
|
|
97
98
|
/** The phrase used for a direction the author did not phrase. */
|
|
@@ -1179,11 +1180,16 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
1179
1180
|
}>>;
|
|
1180
1181
|
}>>;
|
|
1181
1182
|
/**
|
|
1182
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles
|
|
1183
|
-
*
|
|
1183
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, and the
|
|
1184
|
+
* channels whose chats staff may take over from the agent. Written only when declared; absent
|
|
1185
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, and older readers
|
|
1186
|
+
* ignore both.
|
|
1184
1187
|
*/
|
|
1185
1188
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
1186
1189
|
readonly roles: Schema.$Array<Schema.String>;
|
|
1190
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
1191
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
1192
|
+
}>>;
|
|
1187
1193
|
}>>;
|
|
1188
1194
|
/**
|
|
1189
1195
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -1595,6 +1601,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1595
1601
|
} | undefined;
|
|
1596
1602
|
readonly inbox?: {
|
|
1597
1603
|
readonly roles: readonly string[];
|
|
1604
|
+
readonly takeover?: {
|
|
1605
|
+
readonly channels: readonly string[];
|
|
1606
|
+
} | undefined;
|
|
1598
1607
|
} | undefined;
|
|
1599
1608
|
readonly toolsets?: readonly {
|
|
1600
1609
|
readonly name: string;
|
|
@@ -1912,6 +1921,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
1912
1921
|
} | undefined;
|
|
1913
1922
|
readonly inbox?: {
|
|
1914
1923
|
readonly roles: readonly string[];
|
|
1924
|
+
readonly takeover?: {
|
|
1925
|
+
readonly channels: readonly string[];
|
|
1926
|
+
} | undefined;
|
|
1915
1927
|
} | undefined;
|
|
1916
1928
|
readonly toolsets?: readonly {
|
|
1917
1929
|
readonly name: string;
|
|
@@ -2194,6 +2206,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2194
2206
|
} | undefined;
|
|
2195
2207
|
readonly inbox?: {
|
|
2196
2208
|
readonly roles: readonly string[];
|
|
2209
|
+
readonly takeover?: {
|
|
2210
|
+
readonly channels: readonly string[];
|
|
2211
|
+
} | undefined;
|
|
2197
2212
|
} | undefined;
|
|
2198
2213
|
readonly toolsets?: readonly {
|
|
2199
2214
|
readonly name: string;
|
|
@@ -2546,6 +2561,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2546
2561
|
} | undefined;
|
|
2547
2562
|
readonly inbox?: {
|
|
2548
2563
|
readonly roles: readonly string[];
|
|
2564
|
+
readonly takeover?: {
|
|
2565
|
+
readonly channels: readonly string[];
|
|
2566
|
+
} | undefined;
|
|
2549
2567
|
} | undefined;
|
|
2550
2568
|
readonly toolsets?: readonly {
|
|
2551
2569
|
readonly name: string;
|
|
@@ -2891,11 +2909,16 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2891
2909
|
}>>;
|
|
2892
2910
|
}>>;
|
|
2893
2911
|
/**
|
|
2894
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles
|
|
2895
|
-
*
|
|
2912
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, and the
|
|
2913
|
+
* channels whose chats staff may take over from the agent. Written only when declared; absent
|
|
2914
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, and older readers
|
|
2915
|
+
* ignore both.
|
|
2896
2916
|
*/
|
|
2897
2917
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
2898
2918
|
readonly roles: Schema.$Array<Schema.String>;
|
|
2919
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
2920
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
2921
|
+
}>>;
|
|
2899
2922
|
}>>;
|
|
2900
2923
|
/**
|
|
2901
2924
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -3322,11 +3345,16 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3322
3345
|
}>>;
|
|
3323
3346
|
}>>;
|
|
3324
3347
|
/**
|
|
3325
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles
|
|
3326
|
-
*
|
|
3348
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, and the
|
|
3349
|
+
* channels whose chats staff may take over from the agent. Written only when declared; absent
|
|
3350
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, and older readers
|
|
3351
|
+
* ignore both.
|
|
3327
3352
|
*/
|
|
3328
3353
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
3329
3354
|
readonly roles: Schema.$Array<Schema.String>;
|
|
3355
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
3356
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
3357
|
+
}>>;
|
|
3330
3358
|
}>>;
|
|
3331
3359
|
/**
|
|
3332
3360
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
@@ -3730,6 +3758,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3730
3758
|
} | undefined;
|
|
3731
3759
|
readonly inbox?: {
|
|
3732
3760
|
readonly roles: readonly string[];
|
|
3761
|
+
readonly takeover?: {
|
|
3762
|
+
readonly channels: readonly string[];
|
|
3763
|
+
} | undefined;
|
|
3733
3764
|
} | undefined;
|
|
3734
3765
|
readonly toolsets?: readonly {
|
|
3735
3766
|
readonly name: string;
|
|
@@ -4047,6 +4078,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
4047
4078
|
} | undefined;
|
|
4048
4079
|
readonly inbox?: {
|
|
4049
4080
|
readonly roles: readonly string[];
|
|
4081
|
+
readonly takeover?: {
|
|
4082
|
+
readonly channels: readonly string[];
|
|
4083
|
+
} | undefined;
|
|
4050
4084
|
} | undefined;
|
|
4051
4085
|
readonly toolsets?: readonly {
|
|
4052
4086
|
readonly name: string;
|
|
@@ -4370,6 +4404,9 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4370
4404
|
} | undefined;
|
|
4371
4405
|
readonly inbox?: {
|
|
4372
4406
|
readonly roles: readonly string[];
|
|
4407
|
+
readonly takeover?: {
|
|
4408
|
+
readonly channels: readonly string[];
|
|
4409
|
+
} | undefined;
|
|
4373
4410
|
} | undefined;
|
|
4374
4411
|
readonly toolsets?: readonly {
|
|
4375
4412
|
readonly name: string;
|
|
@@ -4687,6 +4724,9 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
|
|
|
4687
4724
|
} | undefined;
|
|
4688
4725
|
readonly inbox?: {
|
|
4689
4726
|
readonly roles: readonly string[];
|
|
4727
|
+
readonly takeover?: {
|
|
4728
|
+
readonly channels: readonly string[];
|
|
4729
|
+
} | undefined;
|
|
4690
4730
|
} | undefined;
|
|
4691
4731
|
readonly toolsets?: readonly {
|
|
4692
4732
|
readonly name: string;
|
|
@@ -4738,6 +4778,16 @@ export declare function signInPolicyOf(manifest: Pick<OntologyManifest, "signIn"
|
|
|
4738
4778
|
export declare function signUpRolesOf(manifest: Pick<OntologyManifest, "signIn">, channel: string): ReadonlyArray<string> | undefined;
|
|
4739
4779
|
/** The wire names of the roles whose people's private chats join the inbox; empty without one. */
|
|
4740
4780
|
export declare function inboxRolesOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
4781
|
+
/** The channels whose private chats staff may take over from the agent; empty without any. */
|
|
4782
|
+
export declare function takeoverChannelsOf(manifest: Pick<OntologyManifest, "inbox">): ReadonlySet<string>;
|
|
4783
|
+
/**
|
|
4784
|
+
* The account providers people write from on the channels staff take chats over on: a platform
|
|
4785
|
+
* channel's kind, whose accounts every channel of the kind shares, and `channel:<name>` for a
|
|
4786
|
+
* workspace channel. Admission names an account's provider, never its channel, so a private chat on
|
|
4787
|
+
* any channel of a listed kind is reported at each message; the report names the channel, and only
|
|
4788
|
+
* a chat on a listed channel is ever held.
|
|
4789
|
+
*/
|
|
4790
|
+
export declare function takeoverProvidersOf(manifest: Pick<OntologyManifest, "inbox" | "chat">): ReadonlySet<string>;
|
|
4741
4791
|
/**
|
|
4742
4792
|
* The websites whose visitors may sign up on `web`, by origin: empty while `web` is closed to
|
|
4743
4793
|
* sign-up. Entries that are not an origin `signUp.origins` accepts are left out.
|
|
@@ -4790,6 +4840,9 @@ export declare function buildManifest(input: {
|
|
|
4790
4840
|
readonly chat?: ChatManifestInput;
|
|
4791
4841
|
readonly inbox?: {
|
|
4792
4842
|
readonly roles: ReadonlyArray<string>;
|
|
4843
|
+
readonly takeover: {
|
|
4844
|
+
readonly channels: ReadonlyArray<string>;
|
|
4845
|
+
};
|
|
4793
4846
|
};
|
|
4794
4847
|
readonly entities: ReadonlyArray<ResolvedEntity>;
|
|
4795
4848
|
readonly roles: ReadonlyArray<Role>;
|
package/dist/manifest.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CHAT_CHANNEL_NAME, CHAT_KINDS } from "./chat-channel.js";
|
|
1
|
+
import { CHAT_CHANNEL_NAME, CHAT_KINDS, channelIdentityProvider, isChatChannelKind, } from "./chat-channel.js";
|
|
2
2
|
import { balancesOf, metricExpression } from "./metric.js";
|
|
3
3
|
import { Effect, Schema, SchemaTransformation } from "effect";
|
|
4
4
|
import { acceptingEarlierManifestNames, withEarlierManifestNames } from "./legacy.js";
|
|
@@ -92,7 +92,8 @@ import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGue
|
|
|
92
92
|
* `channel:<name>`, its people's accounts.
|
|
93
93
|
* Within version 15, the top-level `inbox`, written only when declared, holds the wire names of the
|
|
94
94
|
* `roles` whose people's private chats the agent registers as `agent_chat` records of kind
|
|
95
|
-
* `private
|
|
95
|
+
* `private`, and in `takeover.channels` the channels whose chats staff may take over from the
|
|
96
|
+
* agent. Older readers ignore it, register none and let none be taken over.
|
|
96
97
|
*/
|
|
97
98
|
export const MANIFEST_VERSION = 15;
|
|
98
99
|
/** The first version whose documents use snake_case names on the wire. */
|
|
@@ -562,10 +563,15 @@ const OntologyManifestModel = Schema.Struct({
|
|
|
562
563
|
})),
|
|
563
564
|
})),
|
|
564
565
|
/**
|
|
565
|
-
* Whose private chats join the inbox, within version 15: the wire names of their roles
|
|
566
|
-
*
|
|
566
|
+
* Whose private chats join the inbox, within version 15: the wire names of their roles, and the
|
|
567
|
+
* channels whose chats staff may take over from the agent. Written only when declared; absent
|
|
568
|
+
* registers no private chat, absent `takeover` lets no chat be taken over, and older readers
|
|
569
|
+
* ignore both.
|
|
567
570
|
*/
|
|
568
|
-
inbox: Schema.optionalKey(Schema.Struct({
|
|
571
|
+
inbox: Schema.optionalKey(Schema.Struct({
|
|
572
|
+
roles: Schema.Array(Schema.String),
|
|
573
|
+
takeover: Schema.optionalKey(Schema.Struct({ channels: Schema.Array(Schema.String) })),
|
|
574
|
+
})),
|
|
569
575
|
/**
|
|
570
576
|
* The metrics of the model, since version 8. Written only when there are some; absent reads as
|
|
571
577
|
* none.
|
|
@@ -664,6 +670,24 @@ export function signUpRolesOf(manifest, channel) {
|
|
|
664
670
|
export function inboxRolesOf(manifest) {
|
|
665
671
|
return new Set(manifest.inbox?.roles ?? []);
|
|
666
672
|
}
|
|
673
|
+
/** The channels whose private chats staff may take over from the agent; empty without any. */
|
|
674
|
+
export function takeoverChannelsOf(manifest) {
|
|
675
|
+
return new Set(manifest.inbox?.takeover?.channels ?? []);
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* The account providers people write from on the channels staff take chats over on: a platform
|
|
679
|
+
* channel's kind, whose accounts every channel of the kind shares, and `channel:<name>` for a
|
|
680
|
+
* workspace channel. Admission names an account's provider, never its channel, so a private chat on
|
|
681
|
+
* any channel of a listed kind is reported at each message; the report names the channel, and only
|
|
682
|
+
* a chat on a listed channel is ever held.
|
|
683
|
+
*/
|
|
684
|
+
export function takeoverProvidersOf(manifest) {
|
|
685
|
+
const named = manifest.chat?.channels ?? {};
|
|
686
|
+
return new Set([...takeoverChannelsOf(manifest)].flatMap((name) => {
|
|
687
|
+
const kind = isChatChannelKind(name) ? name : named[name]?.kind;
|
|
688
|
+
return kind === undefined ? [] : [channelIdentityProvider(kind, name)];
|
|
689
|
+
}));
|
|
690
|
+
}
|
|
667
691
|
/**
|
|
668
692
|
* The websites whose visitors may sign up on `web`, by origin: empty while `web` is closed to
|
|
669
693
|
* sign-up. Entries that are not an origin `signUp.origins` accepts are left out.
|
|
@@ -1002,7 +1026,14 @@ export function buildManifest(input) {
|
|
|
1002
1026
|
},
|
|
1003
1027
|
...(Object.keys(emails).length > 0 ? { emails } : {}),
|
|
1004
1028
|
...(input.chat === undefined ? {} : { chat: input.chat }),
|
|
1005
|
-
...(input.inbox === undefined
|
|
1029
|
+
...(input.inbox === undefined
|
|
1030
|
+
? {}
|
|
1031
|
+
: {
|
|
1032
|
+
inbox: {
|
|
1033
|
+
roles: [...input.inbox.roles],
|
|
1034
|
+
takeover: { channels: [...input.inbox.takeover.channels] },
|
|
1035
|
+
},
|
|
1036
|
+
}),
|
|
1006
1037
|
...(connections.length > 0
|
|
1007
1038
|
? {
|
|
1008
1039
|
connections: connections.map((candidate) => ({
|
package/dist/migrate/apply.js
CHANGED
|
@@ -13,12 +13,12 @@ import { prepareReplicationBaseline } from "../replication/baseline.js";
|
|
|
13
13
|
import { randomUUID } from "node:crypto";
|
|
14
14
|
import { recordWorkflowCatalog } from "../runtime/workflow-admission.js";
|
|
15
15
|
import { prepareReplicationEvolution, dropsServingReplicationStorage, refreshReplicationProjection, retainReplicationHistory, renameReplicationHistory, } from "../replication/evolution.js";
|
|
16
|
-
import { migratedReplicationFills
|
|
16
|
+
import { migratedReplicationFills } from "../replication/migrate.js";
|
|
17
17
|
import { AGENT_TASKS_TABLE, ATTACHMENT_SOURCE_CHECK, ATTACHMENT_SOURCES, ATTACHMENTS_TABLE, SIGN_IN_EMAILS_TABLE, WORKFLOW_STARTS_TABLE, } from "../storage/tables.js";
|
|
18
18
|
import { principalsOntology, reconcileWorkflowUsers } from "../runtime/principals.js";
|
|
19
19
|
import { FEDERATION_TABLES } from "../runtime/federation-tables.js";
|
|
20
20
|
import { syncUserIdentities, USER_IDENTITY_ENTITY_ID } from "../runtime/user-identities.js";
|
|
21
|
-
import { resolveReplicationSelection
|
|
21
|
+
import { resolveReplicationSelection } from "../replication/model.js";
|
|
22
22
|
import { ACTION_ATTRIBUTION_TABLE, AGENT_TABLES, API_KEYS_TABLE, CATALOG_TABLE, CHANNEL_USERS_TABLE, OAUTH_GRANTS_GUEST_CHECK, OAUTH_TABLES, USER_ROLES_TABLE, quoteIdentifier, quoteLiteral, historyTableName, } from "./storage.js";
|
|
23
23
|
const CATALOG = quoteIdentifier(CATALOG_TABLE);
|
|
24
24
|
const IDENTITY_SYNC = "Copy members' sign-in identities the legacy identity stores hold.";
|
|
@@ -310,19 +310,13 @@ export const applyMigration = (plan, options) => Effect.gen(function* () {
|
|
|
310
310
|
const previousManifest = yield* readCatalog({ sql });
|
|
311
311
|
let refresh;
|
|
312
312
|
let active;
|
|
313
|
-
let exclusions;
|
|
314
313
|
if (replication?.present) {
|
|
315
314
|
const [state] = yield* sql.unsafe("SELECT * FROM _ontology_replication WHERE id FOR UPDATE");
|
|
316
|
-
if (state && previousManifest) {
|
|
317
|
-
exclusions = yield* Effect.try({
|
|
318
|
-
try: () => migrationReplicationExclusions(previousManifest, plan.target, state.exclusions ?? []),
|
|
319
|
-
catch: (cause) => new CatalogInvalid({ message: "The replication exclusions are invalid.", cause }),
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
315
|
if (state?.enabled) {
|
|
316
|
+
// Every stored business entity replicates; there is no per-workspace export policy.
|
|
323
317
|
refresh = yield* Effect.try({
|
|
324
|
-
try: () => resolveReplicationSelection(plan.target
|
|
325
|
-
catch: (cause) => new CatalogInvalid({ message: "The replication
|
|
318
|
+
try: () => resolveReplicationSelection(plan.target),
|
|
319
|
+
catch: (cause) => new CatalogInvalid({ message: "The replication projection is invalid.", cause }),
|
|
326
320
|
});
|
|
327
321
|
const [target] = presence.targets
|
|
328
322
|
? yield* sql.unsafe("SELECT * FROM _ontology_replication_targets WHERE generation = $1::uuid", [state.active_generation])
|
|
@@ -406,11 +400,6 @@ export const applyMigration = (plan, options) => Effect.gen(function* () {
|
|
|
406
400
|
yield* sql.unsafe("UPDATE _ontology_replication SET version = $1 WHERE id", [
|
|
407
401
|
REPLICATION_SCHEMA_VERSION,
|
|
408
402
|
]);
|
|
409
|
-
if (exclusions !== undefined) {
|
|
410
|
-
yield* sql.unsafe("UPDATE _ontology_replication SET exclusions = $1::jsonb WHERE id", [
|
|
411
|
-
JSON.stringify(exclusions),
|
|
412
|
-
]);
|
|
413
|
-
}
|
|
414
403
|
yield* sql.unsafe("ALTER TABLE _ontology_replication VALIDATE CONSTRAINT _ontology_replication_protocol_floor");
|
|
415
404
|
yield* sql.unsafe("ALTER TABLE _ontology_replication VALIDATE CONSTRAINT _ontology_replication_schema_floor_v5");
|
|
416
405
|
yield* sql.unsafe("ALTER TABLE _ontology_replication VALIDATE CONSTRAINT _ontology_replication_schema_floor_v6");
|
|
@@ -448,7 +437,6 @@ export const applyMigration = (plan, options) => Effect.gen(function* () {
|
|
|
448
437
|
generation: randomUUID(),
|
|
449
438
|
manifest: plan.target,
|
|
450
439
|
selection: refresh,
|
|
451
|
-
exclusions: exclusions ?? [],
|
|
452
440
|
newSource: true,
|
|
453
441
|
}).pipe(Effect.mapError((cause) => new CatalogInvalid({
|
|
454
442
|
message: "Replication initialization could not be prepared.",
|
package/dist/migrate/model.d.ts
CHANGED
|
@@ -562,6 +562,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
562
562
|
} | undefined;
|
|
563
563
|
readonly inbox?: {
|
|
564
564
|
readonly roles: readonly string[];
|
|
565
|
+
readonly takeover?: {
|
|
566
|
+
readonly channels: readonly string[];
|
|
567
|
+
} | undefined;
|
|
565
568
|
} | undefined;
|
|
566
569
|
readonly toolsets?: readonly {
|
|
567
570
|
readonly name: string;
|
|
@@ -879,6 +882,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
879
882
|
} | undefined;
|
|
880
883
|
readonly inbox?: {
|
|
881
884
|
readonly roles: readonly string[];
|
|
885
|
+
readonly takeover?: {
|
|
886
|
+
readonly channels: readonly string[];
|
|
887
|
+
} | undefined;
|
|
882
888
|
} | undefined;
|
|
883
889
|
readonly toolsets?: readonly {
|
|
884
890
|
readonly name: string;
|
|
@@ -1161,6 +1167,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1161
1167
|
} | undefined;
|
|
1162
1168
|
readonly inbox?: {
|
|
1163
1169
|
readonly roles: readonly string[];
|
|
1170
|
+
readonly takeover?: {
|
|
1171
|
+
readonly channels: readonly string[];
|
|
1172
|
+
} | undefined;
|
|
1164
1173
|
} | undefined;
|
|
1165
1174
|
readonly toolsets?: readonly {
|
|
1166
1175
|
readonly name: string;
|
|
@@ -1513,6 +1522,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1513
1522
|
} | undefined;
|
|
1514
1523
|
readonly inbox?: {
|
|
1515
1524
|
readonly roles: readonly string[];
|
|
1525
|
+
readonly takeover?: {
|
|
1526
|
+
readonly channels: readonly string[];
|
|
1527
|
+
} | undefined;
|
|
1516
1528
|
} | undefined;
|
|
1517
1529
|
readonly toolsets?: readonly {
|
|
1518
1530
|
readonly name: string;
|
|
@@ -1795,6 +1807,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
1795
1807
|
}>>;
|
|
1796
1808
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
1797
1809
|
readonly roles: Schema.$Array<Schema.String>;
|
|
1810
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
1811
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
1812
|
+
}>>;
|
|
1798
1813
|
}>>;
|
|
1799
1814
|
readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
1800
1815
|
readonly name: Schema.String;
|
|
@@ -2108,6 +2123,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2108
2123
|
}>>;
|
|
2109
2124
|
readonly inbox: Schema.optionalKey<Schema.Struct<{
|
|
2110
2125
|
readonly roles: Schema.$Array<Schema.String>;
|
|
2126
|
+
readonly takeover: Schema.optionalKey<Schema.Struct<{
|
|
2127
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
2128
|
+
}>>;
|
|
2111
2129
|
}>>;
|
|
2112
2130
|
readonly metrics: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
2113
2131
|
readonly name: Schema.String;
|
|
@@ -2469,6 +2487,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2469
2487
|
} | undefined;
|
|
2470
2488
|
readonly inbox?: {
|
|
2471
2489
|
readonly roles: readonly string[];
|
|
2490
|
+
readonly takeover?: {
|
|
2491
|
+
readonly channels: readonly string[];
|
|
2492
|
+
} | undefined;
|
|
2472
2493
|
} | undefined;
|
|
2473
2494
|
readonly toolsets?: readonly {
|
|
2474
2495
|
readonly name: string;
|
|
@@ -2786,6 +2807,9 @@ export declare const MigrationPlan: Schema.Struct<{
|
|
|
2786
2807
|
} | undefined;
|
|
2787
2808
|
readonly inbox?: {
|
|
2788
2809
|
readonly roles: readonly string[];
|
|
2810
|
+
readonly takeover?: {
|
|
2811
|
+
readonly channels: readonly string[];
|
|
2812
|
+
} | undefined;
|
|
2789
2813
|
} | undefined;
|
|
2790
2814
|
readonly toolsets?: readonly {
|
|
2791
2815
|
readonly name: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import type { SqlClient } from "effect/unstable/sql";
|
|
3
3
|
import type { OntologyManifest } from "../manifest.js";
|
|
4
|
-
import { type ReplicationFills, type ReplicationSelection
|
|
4
|
+
import { type ReplicationFills, type ReplicationSelection } from "./model.js";
|
|
5
5
|
import type { ReplicationLineage } from "./lineage.js";
|
|
6
6
|
export interface ReplicationTarget {
|
|
7
7
|
readonly generation: string;
|
|
@@ -34,7 +34,6 @@ export declare class ReplicationBaselineFailed extends ReplicationBaselineFailed
|
|
|
34
34
|
interface BaselineInput {
|
|
35
35
|
readonly generation: string;
|
|
36
36
|
readonly manifest: OntologyManifest;
|
|
37
|
-
readonly exclusions?: ReadonlyArray<ReplicationExclusion>;
|
|
38
37
|
readonly selection: ReadonlyArray<ReplicationSelection>;
|
|
39
38
|
readonly newSource?: boolean;
|
|
40
39
|
}
|
|
@@ -61,11 +61,12 @@ export const prepareReplicationBaseline = (sql, input) => sql.withTransaction(Ef
|
|
|
61
61
|
yield* sql.unsafe(`INSERT INTO _ontology_replication_targets
|
|
62
62
|
(generation, source_id, from_revision, manifest, selection, protocol, baseline_complete)
|
|
63
63
|
VALUES ($1::uuid, $2::uuid, 0, $3::jsonb, $4::jsonb, 4, false)`, [input.generation, source, JSON.stringify(input.manifest), JSON.stringify(input.selection)]);
|
|
64
|
+
// @legacy ontology.replication-exclusion-remnants
|
|
65
|
+
// An older backend release still reads the retired exclusions; a new baseline has none.
|
|
64
66
|
yield* sql.unsafe(`UPDATE _ontology_replication SET source_id = $1::uuid, selection = $2::jsonb,
|
|
65
|
-
enabled = true, exclusions =
|
|
67
|
+
enabled = true, exclusions = '[]'::jsonb, active_generation = $3::uuid WHERE id`, [
|
|
66
68
|
source,
|
|
67
69
|
JSON.stringify(Object.fromEntries(input.selection.map((s) => [s.entityId, s]))),
|
|
68
|
-
JSON.stringify(input.exclusions ?? []),
|
|
69
70
|
input.generation,
|
|
70
71
|
]);
|
|
71
72
|
if (state.version >= 5) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import type { SqlClient } from "effect/unstable/sql";
|
|
3
3
|
import type { OntologyManifest } from "../manifest.js";
|
|
4
|
-
import { type ReplicationSelection
|
|
4
|
+
import { type ReplicationSelection } from "./model.js";
|
|
5
5
|
export interface ReplicationTarget {
|
|
6
6
|
readonly generation: string;
|
|
7
7
|
readonly source_id: string;
|
|
@@ -20,7 +20,6 @@ export declare class ReplicationBaselineFailed extends ReplicationBaselineFailed
|
|
|
20
20
|
export declare const createReplicationBaseline: (sql: SqlClient.SqlClient, input: {
|
|
21
21
|
readonly generation: string;
|
|
22
22
|
readonly manifest: OntologyManifest;
|
|
23
|
-
readonly exclusions?: ReadonlyArray<ReplicationExclusion>;
|
|
24
23
|
readonly selection: ReadonlyArray<ReplicationSelection>;
|
|
25
24
|
readonly newSource?: boolean;
|
|
26
25
|
}) => Effect.Effect<ReplicationTarget, import("effect/unstable/sql/SqlError").SqlError | import("./baseline.js").ReplicationBaselineFailed | ReplicationBaselineFailed, never>;
|
|
@@ -47,13 +47,10 @@ export const createReplicationBaseline = (sql, input) => sql.withTransaction(Eff
|
|
|
47
47
|
}
|
|
48
48
|
const source = input.newSource ? randomUUID() : state.source_id;
|
|
49
49
|
const selection = Object.fromEntries(input.selection.map((s) => [s.entityId, s]));
|
|
50
|
+
// @legacy ontology.replication-exclusion-remnants
|
|
51
|
+
// An older backend release still reads the retired exclusions; a new baseline has none.
|
|
50
52
|
yield* sql.unsafe(`UPDATE _ontology_replication SET source_id = $1::uuid, selection = $2::jsonb, enabled = true,
|
|
51
|
-
exclusions =
|
|
52
|
-
source,
|
|
53
|
-
JSON.stringify(selection),
|
|
54
|
-
JSON.stringify(input.exclusions ?? []),
|
|
55
|
-
input.generation,
|
|
56
|
-
]);
|
|
53
|
+
exclusions = '[]'::jsonb, active_generation = $3::uuid WHERE id`, [source, JSON.stringify(selection), input.generation]);
|
|
57
54
|
const target = {
|
|
58
55
|
generation: input.generation,
|
|
59
56
|
source_id: source,
|
|
@@ -3,16 +3,7 @@ import type { SqlClient } from "effect/unstable/sql";
|
|
|
3
3
|
import type { OntologyManifest } from "../manifest.js";
|
|
4
4
|
import type { RetainedStorage } from "../migrate/model.js";
|
|
5
5
|
import type { ReplicationTarget } from "./baseline.js";
|
|
6
|
-
import { type
|
|
7
|
-
/** Persist exclusions across temporary removals, and follow a property's logical rename. */
|
|
8
|
-
export declare function migrationReplicationExclusions(current: OntologyManifest, target: OntologyManifest, exclusions: ReadonlyArray<ReplicationExclusion>): ReadonlyArray<ReplicationExclusion>;
|
|
9
|
-
/** Only current declarations participate; retained exclusions still protect a later restoration. */
|
|
10
|
-
export declare function effectiveReplicationExclusions(manifest: OntologyManifest, exclusions: readonly ReplicationExclusion[]): {
|
|
11
|
-
relationships?: ReadonlyArray<string>;
|
|
12
|
-
fields?: ReadonlyArray<string>;
|
|
13
|
-
entityId: string;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
}[];
|
|
6
|
+
import { type ReplicationSelection } from "./model.js";
|
|
16
7
|
/**
|
|
17
8
|
* Fills of the migrated target, read inside the migration transaction after its steps. PostgreSQL gives
|
|
18
9
|
* a field added to an existing entity one value on every row, so any row shows it as capture would
|
|
@@ -3,43 +3,6 @@ import { quoteIdentifier as qi, tableName } from "../migrate/storage.js";
|
|
|
3
3
|
import { renamedReplicationField } from "./lineage.js";
|
|
4
4
|
import { queryFields } from "../query.js";
|
|
5
5
|
import { snapshotExpression } from "./schema.js";
|
|
6
|
-
/** Persist exclusions across temporary removals, and follow a property's logical rename. */
|
|
7
|
-
export function migrationReplicationExclusions(current, target, exclusions) {
|
|
8
|
-
return exclusions.map((item) => ({
|
|
9
|
-
...item,
|
|
10
|
-
...(item.fields === undefined
|
|
11
|
-
? {}
|
|
12
|
-
: {
|
|
13
|
-
fields: item.fields.map((field) => {
|
|
14
|
-
const entity = target.entities.find((entity) => entity.id === item.entityId);
|
|
15
|
-
const renamed = entity?.properties.find((property) => renamedReplicationField(current, target, item.entityId, property.name) === field);
|
|
16
|
-
return renamed?.name ?? field;
|
|
17
|
-
}),
|
|
18
|
-
}),
|
|
19
|
-
}));
|
|
20
|
-
}
|
|
21
|
-
/** Only current declarations participate; retained exclusions still protect a later restoration. */
|
|
22
|
-
export function effectiveReplicationExclusions(manifest, exclusions) {
|
|
23
|
-
return exclusions.flatMap((item) => {
|
|
24
|
-
const entity = manifest.entities.find((entity) => entity.id === item.entityId && !entity.builtIn && !entity.source);
|
|
25
|
-
if (!entity) {
|
|
26
|
-
return [];
|
|
27
|
-
}
|
|
28
|
-
const fields = new Set(queryFields(entity).map((field) => field.name));
|
|
29
|
-
const relationships = new Set(entity.relationships.map((relationship) => relationship.name));
|
|
30
|
-
return [
|
|
31
|
-
{
|
|
32
|
-
...item,
|
|
33
|
-
...(item.fields === undefined
|
|
34
|
-
? {}
|
|
35
|
-
: { fields: item.fields.filter((field) => fields.has(field)) }),
|
|
36
|
-
...(item.relationships === undefined
|
|
37
|
-
? {}
|
|
38
|
-
: { relationships: item.relationships.filter((name) => relationships.has(name)) }),
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
6
|
/**
|
|
44
7
|
* Fills of the migrated target, read inside the migration transaction after its steps. PostgreSQL gives
|
|
45
8
|
* a field added to an existing entity one value on every row, so any row shows it as capture would
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { OntologyManifest } from "../manifest.js";
|
|
2
2
|
/** The current projection of a continuous replication stream. `id` is always included. */
|
|
3
3
|
export interface ReplicationSelection {
|
|
4
4
|
readonly entityId: string;
|
|
@@ -10,14 +10,11 @@ export interface ReplicationSelection {
|
|
|
10
10
|
* captured before the field existed lack its key, while every record they describe holds this value.
|
|
11
11
|
*/
|
|
12
12
|
export type ReplicationFills = Readonly<Record<string, Readonly<Record<string, unknown>>>>;
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
readonly relationships?: ReadonlyArray<string>;
|
|
19
|
-
}
|
|
20
|
-
export declare function resolveReplicationSelection(manifest: OntologyManifest, exclusions?: ReadonlyArray<ReplicationExclusion>): ReadonlyArray<ReplicationSelection>;
|
|
13
|
+
/**
|
|
14
|
+
* Every stored business entity replicates with all of its fields and its relationships between
|
|
15
|
+
* stored business entities. Built-in and warehouse-backed entities are never exported.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveReplicationSelection(manifest: OntologyManifest): ReadonlyArray<ReplicationSelection>;
|
|
21
18
|
export interface ReplicationEvent {
|
|
22
19
|
readonly event_id: string;
|
|
23
20
|
readonly source_id: string;
|
|
@@ -1,53 +1,19 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { isValueMatched } from "../manifest.js";
|
|
3
2
|
import { queryFields } from "../query.js";
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Every stored business entity replicates with all of its fields and its relationships between
|
|
5
|
+
* stored business entities. Built-in and warehouse-backed entities are never exported.
|
|
6
|
+
*/
|
|
7
|
+
export function resolveReplicationSelection(manifest) {
|
|
5
8
|
const entities = manifest.entities.filter((entity) => !entity.builtIn && !entity.source);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const fields = new Set(queryFields(entity).map((field) => field.name));
|
|
15
|
-
const relationships = new Set(entity.relationships.map((relationship) => relationship.name));
|
|
16
|
-
if (item.fields?.some((field) => field === "id" || !fields.has(field))) {
|
|
17
|
-
throw new Error(`Unknown or required replication field on ${entity.name}.`);
|
|
18
|
-
}
|
|
19
|
-
if (item.relationships?.some((relationship) => !relationships.has(relationship))) {
|
|
20
|
-
throw new Error(`Unknown replication relationship on ${entity.name}.`);
|
|
21
|
-
}
|
|
22
|
-
// A value-matched relationship has no `<name>_id`: its reference is the property `on` names.
|
|
23
|
-
const matched = entity.relationships.find((relationship) => item.relationships?.includes(relationship.name) && isValueMatched(relationship));
|
|
24
|
-
if (matched !== undefined) {
|
|
25
|
-
throw new Error(`${entity.name}.${matched.name} is matched by value; exclude its property ` +
|
|
26
|
-
`${matched.on?.property ?? ""} instead.`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const included = entities.filter((entity) => !exclusions.some((item) => item.entityId === entity.id && item.disabled));
|
|
30
|
-
const selection = included.map((entity) => {
|
|
31
|
-
const excluded = exclusions.find((item) => item.entityId === entity.id);
|
|
32
|
-
const keyed = entity.relationships.filter((relationship) => relationship.cardinality === "one" && !isValueMatched(relationship));
|
|
33
|
-
const excludedFields = new Set([
|
|
34
|
-
...(excluded?.fields ?? []),
|
|
35
|
-
...keyed
|
|
36
|
-
.filter((relationship) => excluded?.relationships?.includes(relationship.name))
|
|
37
|
-
.map((relationship) => `${relationship.name}_id`),
|
|
38
|
-
]);
|
|
39
|
-
return {
|
|
40
|
-
entityId: entity.id,
|
|
41
|
-
fields: queryFields(entity)
|
|
42
|
-
.filter((field) => !excludedFields.has(field.name))
|
|
43
|
-
.map((field) => field.name),
|
|
44
|
-
relationships: entity.relationships
|
|
45
|
-
.filter((relationship) => relationship.cardinality === "many" &&
|
|
46
|
-
!excluded?.relationships?.includes(relationship.name) &&
|
|
47
|
-
included.some((target) => target.name === relationship.to))
|
|
48
|
-
.map((relationship) => relationship.name),
|
|
49
|
-
};
|
|
50
|
-
});
|
|
9
|
+
const selection = entities.map((entity) => ({
|
|
10
|
+
entityId: entity.id,
|
|
11
|
+
fields: queryFields(entity).map((field) => field.name),
|
|
12
|
+
relationships: entity.relationships
|
|
13
|
+
.filter((relationship) => relationship.cardinality === "many" &&
|
|
14
|
+
entities.some((target) => target.name === relationship.to))
|
|
15
|
+
.map((relationship) => relationship.name),
|
|
16
|
+
}));
|
|
51
17
|
validateReplicationSelection(manifest, selection);
|
|
52
18
|
return selection;
|
|
53
19
|
}
|
|
@@ -22,6 +22,9 @@ export const REPLICATION_DDL = [
|
|
|
22
22
|
selection jsonb NOT NULL DEFAULT '{}'::jsonb, enabled boolean NOT NULL DEFAULT false
|
|
23
23
|
)`,
|
|
24
24
|
`INSERT INTO _ontology_replication (id, version) VALUES (true, ${REPLICATION_SCHEMA_VERSION}) ON CONFLICT DO NOTHING`,
|
|
25
|
+
// @legacy ontology.replication-exclusion-remnants
|
|
26
|
+
// Retired exclusions: no current reader applies them, but an older backend release still reads
|
|
27
|
+
// the column. The SDK only clears it.
|
|
25
28
|
`ALTER TABLE _ontology_replication ADD COLUMN IF NOT EXISTS exclusions jsonb NOT NULL DEFAULT '[]'::jsonb`,
|
|
26
29
|
`ALTER TABLE _ontology_replication ADD COLUMN IF NOT EXISTS active_generation uuid`,
|
|
27
30
|
`CREATE TABLE IF NOT EXISTS _ontology_replication_targets (
|
|
@@ -116,9 +116,13 @@ export declare const shadowPublicationReady: (sql: SqlClient.SqlClient, epoch: S
|
|
|
116
116
|
export type RetiredShadowSegment = Pick<ShadowSegment, "id" | "job_id">;
|
|
117
117
|
export declare const unfinishedRetiredSegments: (sql: SqlClient.SqlClient) => import("effect/unstable/sql/Statement").Statement<RetiredShadowSegment>;
|
|
118
118
|
export declare const settleRetiredSegment: (sql: SqlClient.SqlClient, segment: RetiredShadowSegment, committed: boolean) => import("effect/unstable/sql/Statement").Statement<object>;
|
|
119
|
-
/**
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Policy-only refresh is independent of build leases and cannot confer publication eligibility.
|
|
121
|
+
* Every change of the active target's projection selects a new active generation, which fences
|
|
122
|
+
* a delayed install of an earlier projection.
|
|
123
|
+
*/
|
|
124
|
+
export declare const shadowPolicyViewOwnership: (sql: SqlClient.SqlClient, generation: string, source: string) => Effect.Effect<boolean, import("effect/unstable/sql/SqlError").SqlError, never>;
|
|
125
|
+
export declare const recordShadowPolicyViews: (sql: SqlClient.SqlClient, generation: string, source: string) => import("effect/unstable/sql/Statement").Statement<object>;
|
|
122
126
|
/** Used after reading a destination view's etag, before its conditional DDL update. */
|
|
123
127
|
export declare const shadowViewOwnership: (sql: SqlClient.SqlClient, id: string) => Effect.Effect<boolean, import("effect/unstable/sql/SqlError").SqlError, never>;
|
|
124
128
|
/** A finite background goal prevents continuous writes from moving initialization's finish line. */
|