@segmentstream/ontology 0.199.0 → 0.200.1
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/analyze.js +10 -3
- package/dist/service/agent/archive-routes.d.ts +2 -2
- package/dist/service/chat/delivery.d.ts +1 -1
- package/dist/service/chat/history-import.d.ts +1 -1
- package/dist/service/chat/history-import.js +4 -1
- package/dist/service/chat/local-reads.d.ts +4 -2
- package/dist/service/chat/local-reads.js +11 -1
- package/dist/service/chat/routes.d.ts +2 -2
- package/dist/service/mcp/server.d.ts +2 -2
- package/dist/service/service.js +8 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.200.1
|
|
4
|
+
|
|
5
|
+
A role can scope `agent_chat:send` to registered destination chat records. The ontology check recognizes the built-in send action's destination check before provider delivery.
|
|
6
|
+
|
|
7
|
+
## 0.200.0
|
|
8
|
+
|
|
9
|
+
An agent preview can import and search chat history in its own database. Existing member permissions and chat scopes apply to the fixture messages. A new preview starts with an empty chat history.
|
|
10
|
+
|
|
3
11
|
## 0.199.0
|
|
4
12
|
|
|
5
13
|
Support sender-verified Telegram Mini App pairing in groups and personal chats. Workspace admission can check the delivery chat and require a Cloud sign-in before the agent starts a turn.
|
package/dist/analyze.js
CHANGED
|
@@ -3790,10 +3790,17 @@ function checkScope(input) {
|
|
|
3790
3790
|
return;
|
|
3791
3791
|
}
|
|
3792
3792
|
const unscopable = entities
|
|
3793
|
-
.flatMap((
|
|
3794
|
-
.find(({ action }) =>
|
|
3793
|
+
.flatMap((entity) => entity.actions.map((action) => ({ entity, action })))
|
|
3794
|
+
.find(({ entity, action }) => {
|
|
3795
|
+
// The built-in agent voice checks its exact destination record in prepare, before sending.
|
|
3796
|
+
const scopedDelivery = permission === "agent_chat:send" &&
|
|
3797
|
+
entity.builtIn &&
|
|
3798
|
+
entity.name === AgentChat.name &&
|
|
3799
|
+
action.name === "send";
|
|
3800
|
+
return (openingPermissions(action).includes(permission) && writesNothing(action) && !scopedDelivery);
|
|
3801
|
+
});
|
|
3795
3802
|
if (unscopable !== undefined) {
|
|
3796
|
-
report("invalid-scope", path, `${permission} runs ${unscopable.entity}.${unscopable.action.name}, a readOnly or ` +
|
|
3803
|
+
report("invalid-scope", path, `${permission} runs ${unscopable.entity.name}.${unscopable.action.name}, a readOnly or ` +
|
|
3797
3804
|
"prepare-only action that writes nothing a scope could check; list it as a string, or " +
|
|
3798
3805
|
"give the action a handler that writes the record.");
|
|
3799
3806
|
return;
|
|
@@ -4,13 +4,13 @@ import { type SessionExchange, type TokenVerifier } from "../authentication.js";
|
|
|
4
4
|
import { RequestId } from "../errors.js";
|
|
5
5
|
import { OntologyBackend } from "../runtime-contract.js";
|
|
6
6
|
import { type RuntimeTokenVerifier } from "../runtime-identity.js";
|
|
7
|
-
import { type
|
|
7
|
+
import { type ChatHistorySource } from "../chat/local-reads.js";
|
|
8
8
|
/**
|
|
9
9
|
* Same member scope as MCP, accessible to app clients with their usual bearer/session.
|
|
10
10
|
* @legacy agent.legacy-conversation-routes The route keeps its published path until it is removed.
|
|
11
11
|
*/
|
|
12
12
|
export declare function archiveRoutes(options: {
|
|
13
|
-
readonly transport:
|
|
13
|
+
readonly transport: ChatHistorySource;
|
|
14
14
|
/** The days the ontology declares it keeps its chats' messages, if it declares them. */
|
|
15
15
|
readonly chatRetentionDays?: number | undefined;
|
|
16
16
|
readonly verifyToken: TokenVerifier;
|
|
@@ -41,6 +41,6 @@ agent?: {
|
|
|
41
41
|
readonly fetch?: AgentChannelTransport["fetch"];
|
|
42
42
|
},
|
|
43
43
|
/** The archive a chat's earlier history is imported to; without it nothing is. */
|
|
44
|
-
history?: HistoryArchive,
|
|
44
|
+
history?: HistoryArchive | "workspace",
|
|
45
45
|
/** The chat archive's reads, which find the chat a person writes from on a channel. */
|
|
46
46
|
chats?: ChatArchiveTransport): ChatDeliveryFactory;
|
|
@@ -72,7 +72,7 @@ export declare function historyImporter(input: {
|
|
|
72
72
|
readonly identityToken: string | undefined;
|
|
73
73
|
readonly requestId: string;
|
|
74
74
|
/** @legacy agent.cloud-chat-archive */
|
|
75
|
-
readonly archive: HistoryArchive;
|
|
75
|
+
readonly archive: HistoryArchive | "workspace";
|
|
76
76
|
/** How long the workspace keeps its chats' messages: an older one is not imported. */
|
|
77
77
|
readonly retentionDays: number;
|
|
78
78
|
/** The kind of the agent's channel `name`, which its files' attachments name as their source. */
|
|
@@ -344,7 +344,7 @@ export function historyImporter(input) {
|
|
|
344
344
|
}
|
|
345
345
|
const store = backend.agents?.chatMessages;
|
|
346
346
|
// The store holds the agent's messages: the chat's history joins them there.
|
|
347
|
-
if (store !== undefined && (yield* store.holds())) {
|
|
347
|
+
if (store !== undefined && (input.archive === "workspace" || (yield* store.holds()))) {
|
|
348
348
|
const kind = input.channelKind(history.provider);
|
|
349
349
|
return yield* importLocally({
|
|
350
350
|
backend,
|
|
@@ -358,6 +358,9 @@ export function historyImporter(input) {
|
|
|
358
358
|
: "channel",
|
|
359
359
|
});
|
|
360
360
|
}
|
|
361
|
+
if (input.archive === "workspace") {
|
|
362
|
+
return yield* new ActionRejected({ message: "The workspace chat store is unavailable." });
|
|
363
|
+
}
|
|
361
364
|
// @legacy agent.cloud-chat-archive Until the agent records into the store, the archive in
|
|
362
365
|
// Cloud takes the history, as it takes the agent's messages: text alone.
|
|
363
366
|
if (uploads.length > 0 ||
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ChatMessage } from "../../runtime/chat-messages.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type ChatArchiveTransport } from "../agent/chat-archive.js";
|
|
3
3
|
import type { OntologyBackend } from "../runtime-contract.js";
|
|
4
|
+
/** A preview reads its own branch even before the first message is imported. */
|
|
5
|
+
export type ChatHistorySource = ChatArchiveTransport | "workspace";
|
|
4
6
|
/**
|
|
5
7
|
* A message of the workspace's chat store as an event of the chat archive's pages, which
|
|
6
8
|
* `chat_history` and `chat_search` have always answered: the archive's fields, and the message's
|
|
@@ -70,4 +72,4 @@ export declare function chatMessageEvent(message: ChatMessage): {
|
|
|
70
72
|
* (`internal`). Reads after a `revision`, or before a cursor of the store, are the store's alone.
|
|
71
73
|
* Any other read goes to `transport`, within the retention the ontology declares, `retentionDays`.
|
|
72
74
|
*/
|
|
73
|
-
export declare function withChatStore(transport:
|
|
75
|
+
export declare function withChatStore(transport: ChatHistorySource, backend: OntologyBackend["Service"], retentionDays: number | undefined): ChatArchiveTransport;
|
|
@@ -2,6 +2,7 @@ import { Clock, Effect } from "effect";
|
|
|
2
2
|
import { ActionRejected, PermissionDenied } from "../../errors.js";
|
|
3
3
|
import { isAllowed } from "../../permissions.js";
|
|
4
4
|
import { parseChatCursor, } from "../../runtime/chat-messages.js";
|
|
5
|
+
import { ChatArchiveUnavailable } from "../agent/chat-archive.js";
|
|
5
6
|
/** A cursor of the chat archive in Cloud: its sequence, negative for imported history. */
|
|
6
7
|
const ARCHIVE_SEQUENCE = /^-?\d+$/;
|
|
7
8
|
/** The sender the chat archive gives the agent's own messages; `author` says it now. */
|
|
@@ -107,15 +108,24 @@ export function withChatStore(transport, backend, retentionDays) {
|
|
|
107
108
|
? undefined
|
|
108
109
|
: { channel: search.provider, chatId: search.chatId };
|
|
109
110
|
if (store === undefined ||
|
|
110
|
-
!(
|
|
111
|
+
!(transport === "workspace" ||
|
|
112
|
+
after !== undefined ||
|
|
111
113
|
cursor !== undefined ||
|
|
112
114
|
(search.before === undefined && (yield* store.holds(chat))))) {
|
|
113
115
|
// @legacy agent.cloud-chat-archive A chat the store does not hold, a search of every chat
|
|
114
116
|
// while the store holds no message, and a page of the archive's own are read from the
|
|
115
117
|
// chat archive in Cloud. A chat whose messages the store purged reads there too, never
|
|
116
118
|
// beyond the declared retention.
|
|
119
|
+
if (transport === "workspace") {
|
|
120
|
+
return yield* new ChatArchiveUnavailable({
|
|
121
|
+
diagnostic: "workspace_chat_store_unavailable",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
117
124
|
return yield* transport(withinRetention(input, retentionDays, yield* Clock.currentTimeMillis));
|
|
118
125
|
}
|
|
126
|
+
if (transport === "workspace" && search.before !== undefined && cursor === undefined) {
|
|
127
|
+
return yield* new ActionRejected({ message: "invalid_chat_cursor" });
|
|
128
|
+
}
|
|
119
129
|
const { principal, memberGroups, chats } = input;
|
|
120
130
|
const key = chat === undefined ? undefined : `${chat.channel}:${chat.chatId}`;
|
|
121
131
|
// A service, such as a workflow's user, reads only the exact chats the ontology checked.
|
|
@@ -8,15 +8,15 @@ import type { BuiltApi } from "../api.js";
|
|
|
8
8
|
import type { AfterCommitHook } from "../config.js";
|
|
9
9
|
import type { ConnectionTransportFactory } from "../connections.js";
|
|
10
10
|
import type { ReplicationKick } from "../replication.js";
|
|
11
|
-
import { type ChatArchiveTransport } from "../agent/chat-archive.js";
|
|
12
11
|
import type { ChatDeliveryFactory } from "./delivery.js";
|
|
12
|
+
import { type ChatHistorySource } from "./local-reads.js";
|
|
13
13
|
export declare function chatRoutes(options: {
|
|
14
14
|
readonly built: BuiltApi;
|
|
15
15
|
readonly hooks: ReadonlyMap<string, AfterCommitHook>;
|
|
16
16
|
readonly connections: ConnectionTransportFactory;
|
|
17
17
|
readonly replicate: ReplicationKick;
|
|
18
18
|
readonly chatDelivery: ChatDeliveryFactory;
|
|
19
|
-
readonly chatHistory?:
|
|
19
|
+
readonly chatHistory?: ChatHistorySource;
|
|
20
20
|
readonly verifyToken: TokenVerifier;
|
|
21
21
|
readonly verifyRuntime?: RuntimeTokenVerifier;
|
|
22
22
|
readonly exchangeSession?: SessionExchange;
|
|
@@ -5,9 +5,9 @@ import type { MetricQueries } from "../metric-query.js";
|
|
|
5
5
|
import { type Decide } from "../decisions.js";
|
|
6
6
|
import type { BuiltApi } from "../api.js";
|
|
7
7
|
import { type TokenVerifier } from "../authentication.js";
|
|
8
|
+
import { type ChatHistorySource } from "../chat/local-reads.js";
|
|
8
9
|
import type { PageCatalogV1 } from "../../navigation-catalog.js";
|
|
9
10
|
import type { AfterCommitHook } from "../config.js";
|
|
10
|
-
import { type ChatArchiveTransport } from "../agent/chat-archive.js";
|
|
11
11
|
import type { ConnectionTransportFactory } from "../connections.js";
|
|
12
12
|
import { RequestId } from "../errors.js";
|
|
13
13
|
import type { ReplicationKick } from "../replication.js";
|
|
@@ -33,7 +33,7 @@ export interface McpServerOptions {
|
|
|
33
33
|
readonly metricQueries: MetricQueries;
|
|
34
34
|
/** Authenticated exact-text delivery for the built-in chat action. */
|
|
35
35
|
readonly chatDelivery?: ChatDeliveryFactory | undefined;
|
|
36
|
-
readonly chatHistory?:
|
|
36
|
+
readonly chatHistory?: ChatHistorySource | undefined;
|
|
37
37
|
/** The workspace whose workflows' tasks authenticate here; without it the task header is refused. */
|
|
38
38
|
readonly workspaceId?: string | undefined;
|
|
39
39
|
/** How `discover` asks the ontology's decision model: AI Gateway by default. Tests replace it. */
|
package/dist/service/service.js
CHANGED
|
@@ -398,7 +398,9 @@ export function createOntologyService(ontology, config) {
|
|
|
398
398
|
: localConnections(config.localConnections)));
|
|
399
399
|
const replicate = deployedReplication(config);
|
|
400
400
|
// The platform keeps chat history for production agents only.
|
|
401
|
-
const
|
|
401
|
+
const cloudChatHistory = config.runtimeIdentity === undefined || preview ? undefined : platformChatArchive(config);
|
|
402
|
+
// Provisioning clears the copied chat store. Preview history always stays in this branch.
|
|
403
|
+
const chatHistory = previewAgent ? "workspace" : cloudChatHistory;
|
|
402
404
|
// @legacy agent.cloud-chat-archive Deliveries reserve here while the store holds no message.
|
|
403
405
|
const deliveries = config.chatArchive ?? platformDeliveryArchive(config);
|
|
404
406
|
// The app's agent sends through a workspace channel, at the origin it takes its tasks at.
|
|
@@ -406,7 +408,11 @@ export function createOntologyService(ontology, config) {
|
|
|
406
408
|
origin: config.agentOrigin,
|
|
407
409
|
...(config.agentTaskTransport === undefined ? {} : { fetch: config.agentTaskTransport }),
|
|
408
410
|
};
|
|
409
|
-
const chatDelivery = makeChatDelivery(ontology, connections, deliveries, { settings: config.channels?.telegram, ownOrigins: config.appOrigins }, agentChannels,
|
|
411
|
+
const chatDelivery = makeChatDelivery(ontology, connections, deliveries, { settings: config.channels?.telegram, ownOrigins: config.appOrigins }, agentChannels, preview
|
|
412
|
+
? previewAgent
|
|
413
|
+
? "workspace"
|
|
414
|
+
: undefined
|
|
415
|
+
: (config.chatHistoryArchive ?? platformHistoryArchive(config)), cloudChatHistory);
|
|
410
416
|
const metricQueries = makeMetricQueries({
|
|
411
417
|
ontology,
|
|
412
418
|
transport: platformMetricQueries({ ...config, manifestHash: ontology.manifest.hash }),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.200.1",
|
|
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",
|