@segmentstream/ontology 0.209.0 → 0.210.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.210.0
4
+
5
+ A chat now has one optional `description`. Upgrading the ontology combines its existing `purpose` and `when_to_use` text in that field. The agent uses the description in group routing and conversation context. A workspace can use its own language.
6
+
7
+ Action required: before upgrading the ontology, move reads and updates of the two former fields to `description`. Replace exact purpose-key lookups with references to the intended chats. The agent and ontology can be upgraded independently.
8
+
3
9
  ## 0.209.0
4
10
 
5
11
  Workflows can start when the platform records an outcome for their workspace. Declare
package/README.md CHANGED
@@ -1407,7 +1407,7 @@ Without either header the agent may call only the agent routes:
1407
1407
  | `GET /api/ontology/agent/identities/{provider}/{external_id}` | agent | `{ user: { id, name }, roles, agent_tools }`; 404 unpaired, 403 revoked, inactive |
1408
1408
  | `GET /api/ontology/agent/identities` | member | `{ identities }`: the member's live identities |
1409
1409
  | `DELETE /api/ontology/agent/identities/{id}` | member | Revokes one of them: 204 |
1410
- | `POST /api/ontology/agent/chats/seen` | agent | `{ provider, externalId, title, memberId?, leftMemberId?, agentLeft?, migratedFrom? }` → `{ id, title, purpose, whenToUse, handled? }` |
1410
+ | `POST /api/ontology/agent/chats/seen` | agent | `{ provider, externalId, title, memberId?, leftMemberId?, agentLeft?, migratedFrom? }` → `{ id, title, description, handled? }` |
1411
1411
  | `POST /api/ontology/agent/chats/handoff` | agent | `{ provider, externalId, memberId, reason }` → `{ id, handoffAt, handled? }`; 404 for a chat staff do not take over |
1412
1412
  | `POST /api/ontology/agent/chats/messages` | agent | Records one message in `_chat_messages`, once by `(channel, chatId, messageId)` and by `operation` → `{ id, first }`; 409 `operation_conflict` for a replay with another `fingerprint` |
1413
1413
  | `POST /api/ontology/agent/chats/messages/change` | agent | One change to a message: `edit`, `delete`, `reaction`, `status`, `disposition`, `sent` (by `operation`) or `meta` → `{ applied }` |
@@ -1538,9 +1538,9 @@ records `lastMessageAt` at most every 15 minutes, links a paired, active writer
1538
1538
  `members` and unlinks `leftMemberId`, a paired member who left, when linked, or every member
1539
1539
  with `agentLeft: true`, when the agent itself left (the chat stays). With `migratedFrom`, the
1540
1540
  old id of a group that became a supergroup, it moves the old record to `externalId`, or, when
1541
- both are recorded, moves the members and a missing `purpose` and `whenToUse` to the new one and
1541
+ both are recorded, moves the members and a missing `description` to the new one and
1542
1542
  deletes the old one. `provider`, `externalId`, `title` and `lastMessageAt` are
1543
- managed. Members set `purpose` and `whenToUse` with the generated
1543
+ managed. Members set `description` with the generated
1544
1544
  `agent_chat.update`, the chat's only generated action, which sets no relationship: `handledBy`
1545
1545
  changes only through `agent_chat.takeOver` and `agent_chat.handBack`. `agent_chat.importHistory`
1546
1546
  adds a chat's messages from before the agent recorded it, each in its place by its time and once by
@@ -17,8 +17,7 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
17
17
  readonly personaNoticeAt: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
18
18
  readonly personaChangedAt: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
19
19
  readonly agentPersona: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
20
- readonly purpose: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
21
- readonly whenToUse: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
20
+ readonly description: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
22
21
  }, {
23
22
  readonly members: import("./relationship.js").ManyRelationship;
24
23
  readonly handledBy: import("./relationship.js").OneRelationship<true, false, "user">;
@@ -186,8 +185,7 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
186
185
  readonly personaNoticeAt: string | null;
187
186
  readonly personaChangedAt: string | null;
188
187
  readonly agentPersona: string | null;
189
- readonly purpose: string | null;
190
- readonly whenToUse: string | null;
188
+ readonly description: string | null;
191
189
  readonly handledById: string | null;
192
190
  }>, Readonly<Record<never, never>>, "generated">;
193
191
  export type AgentChat = typeof AgentChat.Type;
@@ -107,18 +107,11 @@ export const AgentChat = entity("agent_chat", {
107
107
  label: "Agent persona",
108
108
  description: "The persona assigned to this chat. Empty inherits the workspace's chat rules and default.",
109
109
  }),
110
- purpose: p.text({
110
+ description: p.text({
111
111
  optional: true,
112
- maxLength: 64,
113
- description: "A short key that code and agents look the chat up by, such as support.",
114
- }),
115
- whenToUse: p.text({
116
- optional: true,
117
- maxLength: 1000,
112
+ maxLength: 1200,
118
113
  display: "multiline",
119
- label: "When to use",
120
- description: "For agents: what the chat is for and when to write there, such as " +
121
- '"Order questions; the team answers on weekdays."',
114
+ description: "What the chat is for and what its participants use it for.",
122
115
  }),
123
116
  },
124
117
  relationships: {
@@ -35,6 +35,7 @@ export function planMigration(input) {
35
35
  const draft = {
36
36
  before: [],
37
37
  catalog: [],
38
+ beforeDrops: [],
38
39
  drops: [],
39
40
  renames: [],
40
41
  indexDrops: [],
@@ -300,6 +301,7 @@ export function planMigration(input) {
300
301
  steps: [
301
302
  ...draft.before,
302
303
  ...draft.catalog,
304
+ ...draft.beforeDrops,
303
305
  ...draft.drops,
304
306
  ...draft.renames,
305
307
  ...draft.indexDrops,
@@ -328,6 +330,24 @@ function builtInValues(entity, property) {
328
330
  ]
329
331
  : [];
330
332
  }
333
+ /** Fill the new field while the previous manifest's columns still exist, even with allowDrops. */
334
+ function chatDescriptionBackfill(current) {
335
+ if (current.id !== "ent_agent_chat") {
336
+ return undefined;
337
+ }
338
+ const previous = new Set(current.properties.map(({ name }) => name));
339
+ const usage = previous.has("when_to_use") ? "when_to_use" : "whenToUse";
340
+ const columns = ["purpose", usage].filter((name) => previous.has(name)).map(quoteIdentifier);
341
+ if (columns.length === 0) {
342
+ return undefined;
343
+ }
344
+ const values = columns.map((column) => `NULLIF(${column}, '')`);
345
+ const [purpose, guidance] = values;
346
+ const merged = guidance ? `concat_ws(' ', ${purpose}, NULLIF(${guidance}, ${purpose}))` : purpose;
347
+ const hasText = values.map((value) => `${value} IS NOT NULL`).join(" OR ");
348
+ return (`UPDATE ${quoteIdentifier(tableName(current.name))} SET "description" = NULLIF(${merged}, '') ` +
349
+ `WHERE ${hasText}`);
350
+ }
331
351
  /**
332
352
  * A deploy that drops a browser sign-in method is refused while an active member would lose access:
333
353
  * every established email member needs a SegmentStream identity to drop email, and every member with
@@ -1826,7 +1846,9 @@ function planEntityChanges(input) {
1826
1846
  `ADD COLUMN ${columnDefinition(column)}`,
1827
1847
  ...(check === undefined ? [] : [`ADD ${constraintDefinition(check)}`]),
1828
1848
  ];
1829
- draft.additions.push(step({
1849
+ const backfill = property.name === "description" ? chatDescriptionBackfill(pair.current) : undefined;
1850
+ const phase = backfill ? draft.beforeDrops : draft.additions;
1851
+ phase.push(step({
1830
1852
  kind: "addProperty",
1831
1853
  classification: "additive",
1832
1854
  validatesData: column.notNull && column.default === undefined,
@@ -1835,6 +1857,7 @@ function planEntityChanges(input) {
1835
1857
  ...(enumStorage === undefined ? [] : [createEnumStatement(enumStorage)]),
1836
1858
  alterTable(table, actions.join(", ")),
1837
1859
  ...builtInValues(entity, property.name),
1860
+ ...(backfill ? [backfill] : []),
1838
1861
  ],
1839
1862
  }));
1840
1863
  }
@@ -107,6 +107,17 @@ const DRAFT_CONTENT_FIELDS = [
107
107
  function nullableText(value) {
108
108
  return value === null || value === undefined ? null : String(value);
109
109
  }
110
+ /** @legacy agent.chat-description: an older agent requires both former keys on the wire. */
111
+ function chatRegistryResponse(chat) {
112
+ const description = nullableText(chat.description);
113
+ return {
114
+ id: String(chat.id),
115
+ title: String(chat.title),
116
+ description,
117
+ purpose: null,
118
+ whenToUse: description,
119
+ };
120
+ }
110
121
  function pairingOf(row) {
111
122
  return {
112
123
  id: String(row.id),
@@ -731,8 +742,7 @@ export function sqlAgentStore(ontology, sql) {
731
742
  // and the old one is deleted.
732
743
  const kept = {};
733
744
  for (const key of [
734
- "purpose",
735
- "when_to_use",
745
+ "description",
736
746
  "agent_persona",
737
747
  "persona_changed_at",
738
748
  "group_access",
@@ -833,12 +843,7 @@ export function sqlAgentStore(ontology, sql) {
833
843
  // link again when they write after the agent is back.
834
844
  yield* releaseMembers(String(chat.id));
835
845
  }
836
- return {
837
- id: String(chat.id),
838
- title: String(chat.title),
839
- purpose: nullableText(chat.purpose),
840
- whenToUse: nullableText(chat.when_to_use),
841
- };
846
+ return chatRegistryResponse(chat);
842
847
  }))
843
848
  .pipe(Effect.orDie),
844
849
  seeInboxChat: (input) => Effect.gen(function* () {
@@ -950,10 +955,7 @@ export function sqlAgentStore(ontology, sql) {
950
955
  });
951
956
  }
952
957
  return {
953
- id: String(chat.id),
954
- title: String(chat.title),
955
- purpose: nullableText(chat.purpose),
956
- whenToUse: nullableText(chat.when_to_use),
958
+ ...chatRegistryResponse(chat),
957
959
  // A member of staff took the chat over, or the agent handed the person over to staff:
958
960
  // the agent records the person and answers none.
959
961
  ...(((chat.handled_by_id ?? null) !== null || (chat.handoff_at ?? null) !== null) &&
@@ -1067,12 +1069,7 @@ export function sqlAgentStore(ontology, sql) {
1067
1069
  values: { last_message_at: now.toISOString() },
1068
1070
  })
1069
1071
  : found;
1070
- return {
1071
- id: String(chat.id),
1072
- title: String(chat.title),
1073
- purpose: nullableText(chat.purpose),
1074
- whenToUse: nullableText(chat.when_to_use),
1075
- };
1072
+ return chatRegistryResponse(chat);
1076
1073
  }));
1077
1074
  }).pipe(Effect.orDie),
1078
1075
  holdReply: (input) => hold(input.key, input.memberId, () => Effect.succeed({ kind: "reply", reply: input })).pipe(Effect.map((held) => (held === "discarded" ? undefined : held))),
@@ -590,6 +590,8 @@ export declare class IdentityInUse extends IdentityInUse_base {
590
590
  export interface SeenChat {
591
591
  readonly id: string;
592
592
  readonly title: string;
593
+ readonly description: string | null;
594
+ /** @legacy agent.chat-description: accepted by agents predating description. */
593
595
  readonly purpose: string | null;
594
596
  readonly whenToUse: string | null;
595
597
  /**
@@ -694,7 +696,7 @@ export interface AgentStore {
694
696
  * member, and unlinks `leftMemberId`, a member who left, when linked. With `agentLeft`, the agent
695
697
  * itself left the chat: every member is unlinked, and the chat stays. With `migratedFrom`, the
696
698
  * chat had that id before it became a supergroup: its record moves to `externalId`, or, when both
697
- * ids have one, the new record takes the old one's members, and its purpose and when to use where
699
+ * ids have one, the new record takes the old one's members, and its description where
698
700
  * it has none. Concurrent calls for one chat leave one record.
699
701
  */
700
702
  readonly claimChatPersonaNotice?: (id: string, memberId: string) => Effect.Effect<boolean>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.209.0",
3
+ "version": "0.210.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",