@segmentstream/ontology 0.141.0 → 0.142.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 +8 -0
- package/dist/agent-chat.d.ts +7 -0
- package/dist/agent-chat.js +17 -0
- package/dist/migrate/plan.js +14 -0
- package/dist/runtime/agents.js +10 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.142.0
|
|
4
|
+
|
|
5
|
+
Every `agent_chat` record has a unique `key`, `<provider>:<externalId>`, such as
|
|
6
|
+
`telegram:-100123` or `web:guest:<id>`, as the chat archive names the chat. The migration that adds
|
|
7
|
+
it keys the chats already recorded, and the agent keys every chat it records from then on. A
|
|
8
|
+
warehouse-backed entity relates to `AgentChat` on it, such as a model of analytics events a
|
|
9
|
+
website tagged with the chat's key: `rel.one(AgentChat, { inverse: "visits", on: { chat: "key" } })`.
|
|
10
|
+
|
|
3
11
|
## 0.141.0
|
|
4
12
|
|
|
5
13
|
`chat_history` reads a Slack channel's history, every thread of it, as the archive now keeps a
|
package/dist/agent-chat.d.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
export declare const TELEGRAM = "telegram";
|
|
3
|
+
/**
|
|
4
|
+
* A chat's key: its channel and its id there, `<channel>:<id>`, as the chat archive and the agent's
|
|
5
|
+
* requests name the chat, such as `telegram:-100123` or `web:guest:<id>`.
|
|
6
|
+
*/
|
|
7
|
+
export declare function agentChatKey(provider: string, externalId: string): string;
|
|
3
8
|
/** Existing chat registry and membership storage; delivery lives in the ontology service. */
|
|
4
9
|
export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
5
10
|
readonly provider: import("./property.js").Property<string, false, false>;
|
|
6
11
|
readonly kind: import("./property.js").Property<"private" | "group", true, false>;
|
|
7
12
|
readonly externalId: import("./property.js").Property<string, false, false>;
|
|
13
|
+
readonly key: Schema.optionalKey<import("./property.js").Property<string, false, true>>;
|
|
8
14
|
readonly title: import("./property.js").Property<string, false, false>;
|
|
9
15
|
readonly recipient: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
10
16
|
readonly threadId: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
@@ -108,6 +114,7 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
|
108
114
|
readonly provider: string;
|
|
109
115
|
readonly kind: "private" | "group";
|
|
110
116
|
readonly externalId: string;
|
|
117
|
+
readonly key: string | null;
|
|
111
118
|
readonly title: string;
|
|
112
119
|
readonly recipient: string | null;
|
|
113
120
|
readonly threadId: string | null;
|
package/dist/agent-chat.js
CHANGED
|
@@ -6,6 +6,13 @@ import { ChatDelivery, ChatHistoryImportInput, ChatPostInput, ChatSendInput } fr
|
|
|
6
6
|
import { p } from "./property.js";
|
|
7
7
|
import { rel } from "./relationship.js";
|
|
8
8
|
export const TELEGRAM = "telegram";
|
|
9
|
+
/**
|
|
10
|
+
* A chat's key: its channel and its id there, `<channel>:<id>`, as the chat archive and the agent's
|
|
11
|
+
* requests name the chat, such as `telegram:-100123` or `web:guest:<id>`.
|
|
12
|
+
*/
|
|
13
|
+
export function agentChatKey(provider, externalId) {
|
|
14
|
+
return `${provider}:${externalId}`;
|
|
15
|
+
}
|
|
9
16
|
/** Existing chat registry and membership storage; delivery lives in the ontology service. */
|
|
10
17
|
export const AgentChat = entity("agent_chat", {
|
|
11
18
|
id: "ent_agent_chat",
|
|
@@ -27,6 +34,16 @@ export const AgentChat = entity("agent_chat", {
|
|
|
27
34
|
description: "Whether the chat is a group chat or a person's private chat with the agent.",
|
|
28
35
|
}),
|
|
29
36
|
externalId: p.text({ managed: true, description: "The chat's id at the provider." }),
|
|
37
|
+
// Optional only for the records a deploy before it holds, which the migration that adds it
|
|
38
|
+
// keys: every record has one.
|
|
39
|
+
key: p.text({
|
|
40
|
+
optional: true,
|
|
41
|
+
unique: true,
|
|
42
|
+
managed: true,
|
|
43
|
+
description: "The chat's key, `<provider>:<externalId>`, such as `web:guest:<id>` or " +
|
|
44
|
+
"`telegram:-100123`, as the chat archive names the chat. Analytics events and other " +
|
|
45
|
+
"records tag a chat with it, so a warehouse-backed entity relates to the chat on it.",
|
|
46
|
+
}),
|
|
30
47
|
title: p.text({
|
|
31
48
|
managed: true,
|
|
32
49
|
description: "The chat's name at the provider, kept current by the agent: a private chat's is its " +
|
package/dist/migrate/plan.js
CHANGED
|
@@ -297,6 +297,19 @@ export function planMigration(input) {
|
|
|
297
297
|
...retainedField(retainedAfter(renamed)),
|
|
298
298
|
};
|
|
299
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* What a property the platform adds to one of its built-in entities holds in the records the entity
|
|
302
|
+
* already has: the agent chat's `key` is its channel and its id there, as the runtime writes it for
|
|
303
|
+
* the chats it records from then on.
|
|
304
|
+
*/
|
|
305
|
+
function builtInValues(entity, property) {
|
|
306
|
+
return entity === "agent_chat" && property === "key"
|
|
307
|
+
? [
|
|
308
|
+
`UPDATE ${quoteIdentifier(tableName(entity))} SET "key" = "provider" || ':' || ` +
|
|
309
|
+
`"external_id" WHERE "key" IS NULL`,
|
|
310
|
+
]
|
|
311
|
+
: [];
|
|
312
|
+
}
|
|
300
313
|
/**
|
|
301
314
|
* A deploy that drops a browser sign-in method is refused while an active member would lose access:
|
|
302
315
|
* every established email member needs a SegmentStream identity to drop email, and every member with
|
|
@@ -1774,6 +1787,7 @@ function planEntityChanges(input) {
|
|
|
1774
1787
|
sql: [
|
|
1775
1788
|
...(enumStorage === undefined ? [] : [createEnumStatement(enumStorage)]),
|
|
1776
1789
|
alterTable(table, actions.join(", ")),
|
|
1790
|
+
...builtInValues(entity, property.name),
|
|
1777
1791
|
],
|
|
1778
1792
|
}));
|
|
1779
1793
|
}
|
package/dist/runtime/agents.js
CHANGED
|
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
|
|
|
3
3
|
import { Effect, Option, Schema } from "effect";
|
|
4
4
|
import { SqlClient } from "effect/unstable/sql";
|
|
5
5
|
import { action } from "../action.js";
|
|
6
|
-
import { AgentChat } from "../agent-chat.js";
|
|
6
|
+
import { AgentChat, agentChatKey } from "../agent-chat.js";
|
|
7
7
|
import { chatChannelKind } from "../chat-channel.js";
|
|
8
8
|
import { AgentReview } from "../agent-review.js";
|
|
9
9
|
import { AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, CHANNEL_USERS_TABLE, IDENTITY_NOTICES_TABLE, USER_TABLE, } from "../migrate/storage.js";
|
|
@@ -560,7 +560,7 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
560
560
|
found = yield* runtime.update({
|
|
561
561
|
entity: AgentChat.name,
|
|
562
562
|
id: String(old.id),
|
|
563
|
-
values: { external_id: externalId },
|
|
563
|
+
values: { external_id: externalId, key: agentChatKey(provider, externalId) },
|
|
564
564
|
});
|
|
565
565
|
}
|
|
566
566
|
else if (old !== undefined && found !== undefined) {
|
|
@@ -592,7 +592,12 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
592
592
|
const chat = found === undefined
|
|
593
593
|
? yield* runtime.create({
|
|
594
594
|
entity: AgentChat.name,
|
|
595
|
-
values: {
|
|
595
|
+
values: {
|
|
596
|
+
provider,
|
|
597
|
+
external_id: externalId,
|
|
598
|
+
key: agentChatKey(provider, externalId),
|
|
599
|
+
...changes,
|
|
600
|
+
},
|
|
596
601
|
})
|
|
597
602
|
: Object.keys(changes).length === 0
|
|
598
603
|
? found
|
|
@@ -688,6 +693,7 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
688
693
|
values: {
|
|
689
694
|
provider: input.provider,
|
|
690
695
|
external_id: input.externalId,
|
|
696
|
+
key: agentChatKey(input.provider, input.externalId),
|
|
691
697
|
kind: "private",
|
|
692
698
|
...changes,
|
|
693
699
|
},
|
|
@@ -828,6 +834,7 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
828
834
|
values: {
|
|
829
835
|
provider: WEB_PROVIDER,
|
|
830
836
|
external_id: externalId,
|
|
837
|
+
key: agentChatKey(WEB_PROVIDER, externalId),
|
|
831
838
|
kind: "private",
|
|
832
839
|
title: externalId,
|
|
833
840
|
last_message_at: now.toISOString(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.142.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",
|