@segmentstream/ontology 0.193.1 → 0.194.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 +4 -0
- package/dist/agent-chat.d.ts +3 -5
- package/dist/agent-chat.js +21 -9
- package/dist/chat-channel.d.ts +5 -0
- package/dist/chat-channel.js +7 -0
- package/dist/chat-personas.d.ts +4 -1
- package/dist/chat-personas.js +5 -3
- package/dist/runtime/agents.js +6 -1
- package/dist/service/agent/server.js +1 -1
- package/dist/service/runtime-contract.d.ts +4 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.194.0
|
|
4
|
+
|
|
5
|
+
Keep the persona and its system instructions for the lifetime of a session. A changed chat assignment starts a fresh session in the same conversation. Browser clients retry an unaccepted message in the new session.
|
|
6
|
+
|
|
3
7
|
## 0.193.1
|
|
4
8
|
|
|
5
9
|
Select a chat persona consistently across senders and threads. Resolve chat settings and live turns from the same chat address, and provide sandbox and browser guidance with the authorized tools.
|
package/dist/agent-chat.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
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 store 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
|
+
export { agentChatKey } from "./chat-channel.js";
|
|
8
4
|
/** Existing chat registry and membership storage; delivery lives in the ontology service. */
|
|
9
5
|
export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
10
6
|
readonly provider: import("./property.js").Property<string, false, false>;
|
|
@@ -19,6 +15,7 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
|
19
15
|
readonly handoffReason: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
20
16
|
readonly groupAccess: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
21
17
|
readonly personaNoticeAt: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
18
|
+
readonly personaChangedAt: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
22
19
|
readonly agentPersona: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
23
20
|
readonly purpose: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
24
21
|
readonly whenToUse: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
@@ -179,6 +176,7 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
|
|
|
179
176
|
readonly handoffReason: string | null;
|
|
180
177
|
readonly groupAccess: string | null;
|
|
181
178
|
readonly personaNoticeAt: string | null;
|
|
179
|
+
readonly personaChangedAt: string | null;
|
|
182
180
|
readonly agentPersona: string | null;
|
|
183
181
|
readonly purpose: string | null;
|
|
184
182
|
readonly whenToUse: string | null;
|
package/dist/agent-chat.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { chatPersonaNames, deployedChatPersonas } from "./chat-personas.js";
|
|
1
|
+
import { chatPersona, chatPersonaContext, chatPersonaNames, deployedChatPersonas, } from "./chat-personas.js";
|
|
2
2
|
import { Effect, Option, Schema } from "effect";
|
|
3
3
|
import { action } from "./action.js";
|
|
4
4
|
import { AGENT_DRAFT_NOTE_LIMIT } from "./agent-draft.js";
|
|
@@ -8,13 +8,7 @@ import { ChatDelivery, ChatHistoryImportInput, ChatPostInput, ChatSendInput } fr
|
|
|
8
8
|
import { p } from "./property.js";
|
|
9
9
|
import { rel } from "./relationship.js";
|
|
10
10
|
export const TELEGRAM = "telegram";
|
|
11
|
-
|
|
12
|
-
* A chat's key: its channel and its id there, `<channel>:<id>`, as the chat store and the agent's
|
|
13
|
-
* requests name the chat, such as `telegram:-100123` or `web:guest:<id>`.
|
|
14
|
-
*/
|
|
15
|
-
export function agentChatKey(provider, externalId) {
|
|
16
|
-
return `${provider}:${externalId}`;
|
|
17
|
-
}
|
|
11
|
+
export { agentChatKey } from "./chat-channel.js";
|
|
18
12
|
/** Existing chat registry and membership storage; delivery lives in the ontology service. */
|
|
19
13
|
export const AgentChat = entity("agent_chat", {
|
|
20
14
|
id: "ent_agent_chat",
|
|
@@ -100,6 +94,12 @@ export const AgentChat = entity("agent_chat", {
|
|
|
100
94
|
label: "Persona notice",
|
|
101
95
|
description: "When the first authorized member was offered the default persona for this chat.",
|
|
102
96
|
}),
|
|
97
|
+
personaChangedAt: p.timestamp({
|
|
98
|
+
optional: true,
|
|
99
|
+
managed: true,
|
|
100
|
+
label: "Persona changed at",
|
|
101
|
+
description: "Sessions started before this assignment change belong to the previous persona.",
|
|
102
|
+
}),
|
|
103
103
|
agentPersona: p.text({
|
|
104
104
|
optional: true,
|
|
105
105
|
managed: true,
|
|
@@ -185,8 +185,20 @@ export const AgentChat = entity("agent_chat", {
|
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
187
|
const chat = yield* self.get(input.chat, { forUpdate: true });
|
|
188
|
+
const context = chatPersonaContext({
|
|
189
|
+
provider: policy.channelKinds?.[chat.provider] ?? chat.provider,
|
|
190
|
+
channel: chat.provider,
|
|
191
|
+
kind: chat.kind === "private" ? "private" : "group",
|
|
192
|
+
}, chat.externalId);
|
|
193
|
+
const changesPersona = chatPersona(policy, context, chat.agentPersona).name !==
|
|
194
|
+
chatPersona(policy, context, input.persona).name;
|
|
188
195
|
// The scoped write checks record access. A stale selection rolls back the transaction.
|
|
189
|
-
yield* self.update(chat, {
|
|
196
|
+
yield* self.update(chat, {
|
|
197
|
+
agentPersona: input.persona,
|
|
198
|
+
...(changesPersona && {
|
|
199
|
+
personaChangedAt: new Date().toISOString(),
|
|
200
|
+
}),
|
|
201
|
+
});
|
|
190
202
|
if (input.expected !== undefined && input.expected !== (chat.agentPersona ?? null)) {
|
|
191
203
|
return yield* new ActionRejected({
|
|
192
204
|
message: "The assignment changed. Reload this chat before saving.",
|
package/dist/chat-channel.d.ts
CHANGED
|
@@ -45,3 +45,8 @@ export declare function workspaceChannelOf(provider: string): string | undefined
|
|
|
45
45
|
* for the channel named after its kind. Undefined for a name that is neither.
|
|
46
46
|
*/
|
|
47
47
|
export declare function chatChannelKind(chat: Readonly<Record<string, unknown>> | undefined, name: string): ChatKind | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* A chat's key: its channel and its id there, `<channel>:<id>`, as the chat store and the agent's
|
|
50
|
+
* requests name the chat, such as `telegram:-100123` or `web:guest:<id>`.
|
|
51
|
+
*/
|
|
52
|
+
export declare function agentChatKey(provider: string, externalId: string): string;
|
package/dist/chat-channel.js
CHANGED
|
@@ -67,3 +67,10 @@ export function chatChannelKind(chat, name) {
|
|
|
67
67
|
}
|
|
68
68
|
return isChatKind(kind) && name !== WORKSPACE_CHANNEL_KIND ? kind : undefined;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* A chat's key: its channel and its id there, `<channel>:<id>`, as the chat store and the agent's
|
|
72
|
+
* requests name the chat, such as `telegram:-100123` or `web:guest:<id>`.
|
|
73
|
+
*/
|
|
74
|
+
export function agentChatKey(provider, externalId) {
|
|
75
|
+
return `${provider}:${externalId}`;
|
|
76
|
+
}
|
package/dist/chat-personas.d.ts
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
/** Trusted delivery coordinates. The channel is the configured connection's channel name. */
|
|
2
2
|
export interface PersonaContext {
|
|
3
|
+
readonly chat?: string;
|
|
3
4
|
readonly provider: string;
|
|
4
5
|
readonly channel: string;
|
|
5
6
|
readonly kind: "private" | "group";
|
|
6
7
|
readonly audience?: "guest" | "member";
|
|
7
8
|
}
|
|
8
9
|
/** Audience is an attribute of an authenticated web chat address. Shared chats can have mixed audiences. */
|
|
9
|
-
export declare function chatPersonaContext(address: Omit<PersonaContext, "audience">, externalId: string): PersonaContext;
|
|
10
|
+
export declare function chatPersonaContext(address: Omit<PersonaContext, "chat" | "audience">, externalId: string): PersonaContext;
|
|
10
11
|
export interface PersonaRule {
|
|
11
12
|
readonly when: Partial<PersonaContext>;
|
|
12
13
|
readonly use: string;
|
|
13
14
|
}
|
|
14
15
|
/** Deployed selection policy. The ontology only needs names and conditions. */
|
|
15
16
|
export interface ChatPersonaPolicy {
|
|
17
|
+
/** Provider kinds for named channel connections in the deployed policy. */
|
|
18
|
+
readonly channelKinds?: Readonly<Record<string, string>>;
|
|
16
19
|
readonly default?: string;
|
|
17
20
|
readonly available?: readonly string[];
|
|
18
21
|
readonly rules?: readonly PersonaRule[];
|
package/dist/chat-personas.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import { agentChatKey } from "./chat-channel.js";
|
|
1
2
|
/** Audience is an attribute of an authenticated web chat address. Shared chats can have mixed audiences. */
|
|
2
3
|
export function chatPersonaContext(address, externalId) {
|
|
4
|
+
const context = { ...address, chat: agentChatKey(address.channel, externalId) };
|
|
3
5
|
if (address.provider === "web" && address.kind === "private") {
|
|
4
6
|
if (externalId.startsWith("guest:")) {
|
|
5
|
-
return { ...
|
|
7
|
+
return { ...context, audience: "guest" };
|
|
6
8
|
}
|
|
7
9
|
if (externalId.startsWith("member:")) {
|
|
8
|
-
return { ...
|
|
10
|
+
return { ...context, audience: "member" };
|
|
9
11
|
}
|
|
10
12
|
}
|
|
11
|
-
return
|
|
13
|
+
return context;
|
|
12
14
|
}
|
|
13
15
|
export function chatPersonaNames(settings) {
|
|
14
16
|
return [
|
package/dist/runtime/agents.js
CHANGED
|
@@ -650,7 +650,11 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
650
650
|
}),
|
|
651
651
|
readGroupAccess: (key) => rows(`SELECT "group_access" FROM ${quoteIdentifier(tableName(AgentChat.name))}
|
|
652
652
|
WHERE "key" = $1 AND "kind" = 'group' AND "handoff_at" IS NULL AND "handled_by_id" IS NULL`, [key]).pipe(Effect.map(([chat]) => nullableText(chat?.group_access))),
|
|
653
|
-
readChatPersona: (key) => rows(`SELECT "agent_persona" FROM ${quoteIdentifier(tableName(AgentChat.name))}
|
|
653
|
+
readChatPersona: (key) => rows(`SELECT "agent_persona", "persona_changed_at" FROM ${quoteIdentifier(tableName(AgentChat.name))}
|
|
654
|
+
WHERE "key" = $1`, [key]).pipe(Effect.map(([chat]) => ({
|
|
655
|
+
persona: nullableText(chat?.agent_persona),
|
|
656
|
+
changedAt: chat?.persona_changed_at == null ? null : timestampText(chat.persona_changed_at),
|
|
657
|
+
}))),
|
|
654
658
|
seeChat: ({ provider, externalId, title, memberId, leftMemberId, agentLeft, migratedFrom }) => sql
|
|
655
659
|
.withTransaction(Effect.gen(function* () {
|
|
656
660
|
yield* beginReplicationWrite(sql);
|
|
@@ -725,6 +729,7 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
725
729
|
"purpose",
|
|
726
730
|
"when_to_use",
|
|
727
731
|
"agent_persona",
|
|
732
|
+
"persona_changed_at",
|
|
728
733
|
"group_access",
|
|
729
734
|
"persona_notice_at",
|
|
730
735
|
]) {
|
|
@@ -1015,7 +1015,7 @@ export function agentLayer(options) {
|
|
|
1015
1015
|
if (Result.isFailure(decoded)) {
|
|
1016
1016
|
return invalidBody(requestId, schemaIssues(decoded.failure));
|
|
1017
1017
|
}
|
|
1018
|
-
return json(
|
|
1018
|
+
return json(yield* read(decoded.success.key));
|
|
1019
1019
|
})));
|
|
1020
1020
|
}
|
|
1021
1021
|
if (store.readGroupAccess) {
|
|
@@ -689,7 +689,10 @@ export interface AgentStore {
|
|
|
689
689
|
/** Recheck the current chat and sender for every runtime guest tool call. */
|
|
690
690
|
readonly channelGuest?: (channel: string, chat: string, sender: string) => Effect.Effect<Principal | undefined>;
|
|
691
691
|
readonly readGroupAccess?: (key: string) => Effect.Effect<string | null>;
|
|
692
|
-
readonly readChatPersona?: (key: string) => Effect.Effect<
|
|
692
|
+
readonly readChatPersona?: (key: string) => Effect.Effect<{
|
|
693
|
+
readonly persona: string | null;
|
|
694
|
+
readonly changedAt: string | null;
|
|
695
|
+
}>;
|
|
693
696
|
readonly seeChat: (input: {
|
|
694
697
|
readonly provider: string;
|
|
695
698
|
readonly externalId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.194.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",
|