@segmentstream/ontology 0.203.0 → 0.204.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,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.204.0
|
|
4
|
+
|
|
5
|
+
Workflow tasks can read messages from a registered group by record id within their existing `agent_chat:read` scope.
|
|
6
|
+
|
|
7
|
+
## 0.203.1
|
|
8
|
+
|
|
9
|
+
An app that declares `signIn.cli` now asks SegmentStream whether the member's consent still holds
|
|
10
|
+
before it exchanges a CLI token for a grant, so withdrawing the app on segmentstream.com also stops
|
|
11
|
+
a token issued just before.
|
|
12
|
+
|
|
3
13
|
## 0.203.0
|
|
4
14
|
|
|
5
15
|
`signIn.cli: true` lets members' SegmentStream CLI reach the app's MCP server without a device
|
|
@@ -12,29 +12,37 @@ import { chatResolver, groupChatKey, isChatMember } from "./resolve.js";
|
|
|
12
12
|
*/
|
|
13
13
|
const HISTORY_KINDS = new Set(["telegram", "slack"]);
|
|
14
14
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
* `agent_chat:read` whose scope holds the record (`staff`), or the person in it. Its `externalId` is
|
|
18
|
-
* the chat's id in the archive on every channel. `undefined` for any other id.
|
|
19
|
-
*/
|
|
20
|
-
function registeredPrivateChat(backend, principal, id) {
|
|
15
|
+
/** The registered record whose archive the caller may read by id, and how they may read it. */
|
|
16
|
+
function registeredChat(backend, principal, id) {
|
|
21
17
|
return Effect.gen(function* () {
|
|
18
|
+
if (isAllowed("agent_chat:read", principal)) {
|
|
19
|
+
const chat = yield* backend
|
|
20
|
+
.get({ entity: "agent_chat", id, reader: principal })
|
|
21
|
+
.pipe(Effect.catchTag("NotFound", () => Effect.succeed(undefined)));
|
|
22
|
+
if (chat?.kind === "private" || (principal.kind === "service" && chat?.kind === "group")) {
|
|
23
|
+
return { chat, staff: true };
|
|
24
|
+
}
|
|
25
|
+
// Members read groups through the channel's normal group-history rules below.
|
|
26
|
+
if (chat?.kind === "group") {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (principal.kind !== "member") {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
22
33
|
const [chat] = (yield* backend
|
|
23
34
|
.find({
|
|
24
35
|
entity: "agent_chat",
|
|
25
36
|
query: { where: { and: [{ id: { eq: id } }, { kind: { eq: "private" } }] }, limit: 1 },
|
|
26
37
|
})
|
|
27
38
|
.pipe(Effect.mapError((cause) => new ActionRejected({ message: "The chat directory could not be read.", cause })))).items;
|
|
28
|
-
// A group chat is read as before; only a private chat the inbox registered is read here.
|
|
29
39
|
if (chat === undefined || chat.kind !== "private") {
|
|
30
40
|
return undefined;
|
|
31
41
|
}
|
|
32
|
-
|
|
33
|
-
(yield* backend.get({ entity: "agent_chat", id, reader: principal }).pipe(Effect.as(true), Effect.catchTag("NotFound", () => Effect.succeed(false))));
|
|
34
|
-
if (!staff && !(yield* isChatMember(backend, principal, id))) {
|
|
42
|
+
if (!(yield* isChatMember(backend, principal, id))) {
|
|
35
43
|
return yield* new PermissionDenied({ message: "This chat is not readable by the caller." });
|
|
36
44
|
}
|
|
37
|
-
return {
|
|
45
|
+
return { chat, staff: false };
|
|
38
46
|
});
|
|
39
47
|
}
|
|
40
48
|
export function chatReads(backend, options) {
|
|
@@ -80,7 +88,9 @@ export function chatReads(backend, options) {
|
|
|
80
88
|
history: (input, identityToken) => Effect.gen(function* () {
|
|
81
89
|
const principal = yield* CurrentPrincipal;
|
|
82
90
|
if (principal.kind !== "member" && principal.kind !== "service") {
|
|
83
|
-
return yield* new PermissionDenied({
|
|
91
|
+
return yield* new PermissionDenied({
|
|
92
|
+
message: "This chat is not readable by the caller.",
|
|
93
|
+
});
|
|
84
94
|
}
|
|
85
95
|
// A page continues one way: older than a cursor, or changed after a revision.
|
|
86
96
|
if (input.before !== undefined && input.after !== undefined) {
|
|
@@ -88,35 +98,41 @@ export function chatReads(backend, options) {
|
|
|
88
98
|
}
|
|
89
99
|
const after = input.after === undefined ? {} : { after: input.after };
|
|
90
100
|
const registered = UUID.test(input.chat)
|
|
91
|
-
? yield*
|
|
101
|
+
? yield* registeredChat(backend, principal, input.chat)
|
|
92
102
|
: undefined;
|
|
93
103
|
if (registered !== undefined) {
|
|
94
104
|
if (!chatHistory) {
|
|
95
105
|
return yield* new ActionRejected({ message: "The chat archive is not configured." });
|
|
96
106
|
}
|
|
97
|
-
const key =
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
// paired with someone else since shows the earlier person nothing newer.
|
|
107
|
+
const key = groupChatKey(registered.chat);
|
|
108
|
+
// Internal notes are available only on a staff read of a private inbox chat. Its
|
|
109
|
+
// participant reads only messages they took part in, including after a pairing change.
|
|
101
110
|
return yield* chatHistory({
|
|
102
111
|
principal,
|
|
103
112
|
identityToken,
|
|
104
113
|
search: {
|
|
105
|
-
provider: registered.provider,
|
|
106
|
-
chatId: registered.
|
|
114
|
+
provider: String(registered.chat.provider),
|
|
115
|
+
chatId: String(registered.chat.external_id),
|
|
107
116
|
...(input.before === undefined ? {} : { before: input.before }),
|
|
108
117
|
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
109
118
|
},
|
|
110
119
|
memberGroups: [],
|
|
111
120
|
...(registered.staff
|
|
112
|
-
? {
|
|
121
|
+
? {
|
|
122
|
+
chats: [key],
|
|
123
|
+
...(registered.chat.kind === "private" && input.internal === true
|
|
124
|
+
? { internal: true }
|
|
125
|
+
: {}),
|
|
126
|
+
}
|
|
113
127
|
: {}),
|
|
114
128
|
...after,
|
|
115
129
|
});
|
|
116
130
|
}
|
|
117
131
|
// A service, such as a workflow's user, reads only the registered chats its scope holds.
|
|
118
132
|
if (principal.kind !== "member") {
|
|
119
|
-
return yield* new PermissionDenied({
|
|
133
|
+
return yield* new PermissionDenied({
|
|
134
|
+
message: "This chat is not readable by the caller.",
|
|
135
|
+
});
|
|
120
136
|
}
|
|
121
137
|
// History reads Telegram's chats and Slack's channels, which the archive keeps under the
|
|
122
138
|
// chat a destination names. Other channels' chats are read by the record the inbox
|
|
@@ -3,8 +3,14 @@ import type { FederationSession } from "../runtime/federation.js";
|
|
|
3
3
|
export declare function createFederationStatus(options?: {
|
|
4
4
|
fetch?: typeof fetch;
|
|
5
5
|
now?: () => number;
|
|
6
|
-
}): (session: Pick<FederationSession, "issuer" | "clientId" | "consentId" | "generation" | "sessionId">
|
|
7
|
-
|
|
6
|
+
}): (session: Pick<FederationSession, "issuer" | "clientId" | "consentId" | "generation" | "sessionId"> & {
|
|
7
|
+
/** A CLI token's consent, which no browser session carries. */
|
|
8
|
+
readonly use?: "cli";
|
|
9
|
+
}) => Promise<boolean>;
|
|
10
|
+
export declare const federationStatus: (session: Pick<FederationSession, "issuer" | "clientId" | "consentId" | "generation" | "sessionId"> & {
|
|
11
|
+
/** A CLI token's consent, which no browser session carries. */
|
|
12
|
+
readonly use?: "cli";
|
|
13
|
+
}) => Promise<boolean>;
|
|
8
14
|
export interface BrowserRevision {
|
|
9
15
|
readonly issuer: string;
|
|
10
16
|
readonly clientId: string;
|
|
@@ -9,6 +9,7 @@ export function createFederationStatus(options = {}) {
|
|
|
9
9
|
session.consentId,
|
|
10
10
|
session.generation,
|
|
11
11
|
session.sessionId,
|
|
12
|
+
session.use,
|
|
12
13
|
]);
|
|
13
14
|
const cached = cache.get(key);
|
|
14
15
|
if (cached && now() - cached.checkedAt < 55_000) {
|
|
@@ -22,6 +23,7 @@ export function createFederationStatus(options = {}) {
|
|
|
22
23
|
generation: String(session.generation),
|
|
23
24
|
consent: session.consentId,
|
|
24
25
|
...(session.sessionId === undefined ? {} : { session: session.sessionId }),
|
|
26
|
+
...(session.use === undefined ? {} : { use: session.use }),
|
|
25
27
|
}).toString();
|
|
26
28
|
const response = await (options.fetch ?? fetch)(endpoint, {
|
|
27
29
|
cache: "no-store",
|
|
@@ -828,7 +828,8 @@ export function mcpTools(built, chatHistory = false, storage = {}, navigation =
|
|
|
828
828
|
description: "Read messages for an exact chat ID/title, with their own pagination. " +
|
|
829
829
|
"Reads a group chat you are in (every group with agent_chat:read), your own private chat, " +
|
|
830
830
|
"or, by its agent_chat id, a private chat the inbox registered (a person's, or a website " +
|
|
831
|
-
"visitor's), with agent_chat:read within your scope. A workflow
|
|
831
|
+
"visitor's), with agent_chat:read within your scope. A workflow reads a registered group " +
|
|
832
|
+
"or private chat by its agent_chat id within its agent_chat:read scope.",
|
|
832
833
|
inputSchema: encodedJsonSchema(ChatHistory),
|
|
833
834
|
annotations: READ,
|
|
834
835
|
permissions: [],
|
package/dist/service/service.js
CHANGED
|
@@ -49,6 +49,7 @@ import { suggestNames } from "./name-suggestions.js";
|
|
|
49
49
|
import { observeMcpRequest } from "./mcp/request-log.js";
|
|
50
50
|
import { oauthLayer } from "./oauth/server.js";
|
|
51
51
|
import { createFederationProvider } from "./federation-provider.js";
|
|
52
|
+
import { federationStatus } from "./federation-status.js";
|
|
52
53
|
import { federationLayer } from "./federation-server.js";
|
|
53
54
|
import { channelSessionLayer } from "./channel/sessions.js";
|
|
54
55
|
import { channelSignInLayer } from "./channel/sign-in.js";
|
|
@@ -446,7 +447,14 @@ export function createOntologyService(ontology, config) {
|
|
|
446
447
|
? {
|
|
447
448
|
cliExchange: {
|
|
448
449
|
clientId: federationConfig.clientId,
|
|
449
|
-
|
|
450
|
+
// The token is offline evidence; Cloud confirms the member's consent still holds.
|
|
451
|
+
verify: async (token) => {
|
|
452
|
+
const identity = await cliProvider.verifyCliToken(token);
|
|
453
|
+
if (!(await federationStatus({ ...identity, use: "cli" }))) {
|
|
454
|
+
throw new Error("The member's consent to this app is no longer active");
|
|
455
|
+
}
|
|
456
|
+
return identity;
|
|
457
|
+
},
|
|
450
458
|
},
|
|
451
459
|
}
|
|
452
460
|
: {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.204.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",
|