@segmentstream/ontology 0.190.0 → 0.192.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 +18 -0
- package/dist/analyze.js +4 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/runtime-source.d.ts +3 -0
- package/dist/runtime-source.js +11 -0
- package/dist/service/chat/schemas.d.ts +10 -0
- package/dist/service/chat/schemas.js +12 -0
- package/dist/service/mcp/tools.d.ts +2 -2
- package/dist/service/mcp/tools.js +32 -16
- package/dist/service/operations.js +18 -6
- package/dist/workspace-memberships.d.ts +9 -0
- package/dist/workspace-memberships.js +64 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.192.0
|
|
4
|
+
|
|
5
|
+
Apps can opt in to the workspace_memberships sign-in scope with shareWorkspaceMemberships. With the person’s consent, a production ontology action can call workspaceMemberships(principal) during preparation to read current accessible workspace IDs. The person can withdraw consent. Reading workspace content still requires its own grant.
|
|
6
|
+
|
|
7
|
+
## 0.191.0
|
|
8
|
+
|
|
9
|
+
`chat_send` is now an agent session's exact-post tool, as `chat_post_message` has been. Where the
|
|
10
|
+
ontology declares a chat connection, `chat_send` carries the `segmentstream/chat-post` protocol.
|
|
11
|
+
For an agent's session it takes only `chat`, `text`, `reply_to` and `as: "me"`, which it may omit,
|
|
12
|
+
since a session writes in its member's voice alone. As with `chat_post_message`, the key is the
|
|
13
|
+
approved call's, and the service sends only the text the member approved, with the frozen preview's
|
|
14
|
+
destination and digest. A member's own client, and every other caller, still give `chat_send` its
|
|
15
|
+
full input and their own `idempotency_key`.
|
|
16
|
+
|
|
17
|
+
This is the first step of the `chat_post_message` deprecation (`ontology.chat-post-message`): an
|
|
18
|
+
agent SDK that recognizes the protocol on `chat_send` posts through it, and `chat_post_message` keeps
|
|
19
|
+
working for earlier agents until the deprecation's date.
|
|
20
|
+
|
|
3
21
|
## 0.190.0
|
|
4
22
|
|
|
5
23
|
Let a linked member authorize source reads for selected workspaces in a private conversation, with an expiry and revocation.
|
package/dist/analyze.js
CHANGED
|
@@ -1501,8 +1501,8 @@ function checkConnectionsUsed(entities, connections, declared, workflows, report
|
|
|
1501
1501
|
}
|
|
1502
1502
|
/**
|
|
1503
1503
|
* The keys of an action's connections, each listed in `defineOntology({ connections })`, and the
|
|
1504
|
-
* phases they require
|
|
1505
|
-
*
|
|
1504
|
+
* phases they require. Read-only preparations can also query the platform for the current
|
|
1505
|
+
* member. Each action has a preparation or a handler.
|
|
1506
1506
|
*/
|
|
1507
1507
|
function resolveActionConnections(path, action, scope, builtIn) {
|
|
1508
1508
|
const { report } = scope;
|
|
@@ -1538,7 +1538,8 @@ function resolveActionConnections(path, action, scope, builtIn) {
|
|
|
1538
1538
|
!builtIn &&
|
|
1539
1539
|
Array.isArray(declared) &&
|
|
1540
1540
|
declared.length === 0 &&
|
|
1541
|
-
action.files === undefined
|
|
1541
|
+
action.files === undefined &&
|
|
1542
|
+
!(action.hints?.readOnly === true && action.transactional === false)) {
|
|
1542
1543
|
report("invalid-prepare", `${path}.prepare`, "prepare requires connections or file access; declare files: [] for file reads.");
|
|
1543
1544
|
}
|
|
1544
1545
|
if (!hasPrepare && !hasHandler) {
|
package/dist/index.d.ts
CHANGED
|
@@ -121,3 +121,5 @@ export { compiledWorkflowId, triggerPath, vercelWorkflowEngine, WorkflowStepFail
|
|
|
121
121
|
export type { WorkflowEngine, WorkflowPage, WorkflowRunRecord, WorkflowStepRecord, } from "./service/workflows.js";
|
|
122
122
|
export { validateBrowserSignIn } from "./sign-in.js";
|
|
123
123
|
export type { BrowserSignInOptions, BrowserSignInMethod } from "./sign-in.js";
|
|
124
|
+
export { workspaceMemberships } from "./workspace-memberships.js";
|
|
125
|
+
export { isPrivateReply } from "./runtime-source.js";
|
package/dist/index.js
CHANGED
|
@@ -84,3 +84,5 @@ export { RUNTIME_SOURCE_PROVIDERS } from "./runtime-source.js";
|
|
|
84
84
|
export { callbackIdentityToken, serveWorkflowCallback } from "./service/workflow-callback.js";
|
|
85
85
|
export { compiledWorkflowId, triggerPath, vercelWorkflowEngine, WorkflowStepFailed, } from "./service/workflows.js";
|
|
86
86
|
export { validateBrowserSignIn } from "./sign-in.js";
|
|
87
|
+
export { workspaceMemberships } from "./workspace-memberships.js";
|
|
88
|
+
export { isPrivateReply } from "./runtime-source.js";
|
package/dist/runtime-source.d.ts
CHANGED
|
@@ -43,3 +43,6 @@ export type RuntimeSource = typeof RuntimeSource.Type;
|
|
|
43
43
|
export interface ActionRuntime {
|
|
44
44
|
readonly source: RuntimeSource;
|
|
45
45
|
}
|
|
46
|
+
/** Whether a reply to this verified inbound event is delivered directly to the sender.
|
|
47
|
+
* Replies to shared, unknown or unverified destinations may have additional readers. */
|
|
48
|
+
export declare function isPrivateReply(runtime: ActionRuntime | undefined): boolean;
|
package/dist/runtime-source.js
CHANGED
|
@@ -63,3 +63,14 @@ const ChannelRuntimeSource = Schema.Struct({
|
|
|
63
63
|
});
|
|
64
64
|
/** Decoded only at a verified runtime boundary; ordinary action arguments never establish provenance. */
|
|
65
65
|
export const RuntimeSource = Schema.Union([TelegramRuntimeSource, ChannelRuntimeSource]);
|
|
66
|
+
/** Whether a reply to this verified inbound event is delivered directly to the sender.
|
|
67
|
+
* Replies to shared, unknown or unverified destinations may have additional readers. */
|
|
68
|
+
export function isPrivateReply(runtime) {
|
|
69
|
+
const source = runtime?.source;
|
|
70
|
+
if (!source) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return source.provider === "telegram"
|
|
74
|
+
? source.chat_id === source.sender
|
|
75
|
+
: source.kind === "private" && typeof source.sender === "string";
|
|
76
|
+
}
|
|
@@ -58,6 +58,16 @@ export declare const RuntimeChatPostWire: Schema.Struct<{
|
|
|
58
58
|
readonly text: Schema.String;
|
|
59
59
|
readonly reply_to: Schema.optionalKey<Schema.String>;
|
|
60
60
|
}>;
|
|
61
|
+
/**
|
|
62
|
+
* What an agent's session sends: the exact text its member approved, in their voice. The key is
|
|
63
|
+
* the runtime's, from the approved call; the session sends no files, buttons or template.
|
|
64
|
+
*/
|
|
65
|
+
export declare const RuntimeChatSendWire: Schema.Struct<{
|
|
66
|
+
readonly chat: Schema.String;
|
|
67
|
+
readonly text: Schema.String;
|
|
68
|
+
readonly reply_to: Schema.optionalKey<Schema.String>;
|
|
69
|
+
readonly as: Schema.optionalKey<Schema.Literal<"me">>;
|
|
70
|
+
}>;
|
|
61
71
|
export declare const ChatList: Schema.Struct<{
|
|
62
72
|
readonly chat: Schema.optionalKey<Schema.String>;
|
|
63
73
|
readonly query: Schema.optionalKey<Schema.String>;
|
|
@@ -10,6 +10,18 @@ export const RuntimeChatPostWire = Schema.Struct({
|
|
|
10
10
|
text: ChatPostInput.fields.text,
|
|
11
11
|
reply_to: Schema.optionalKey(Id),
|
|
12
12
|
});
|
|
13
|
+
/**
|
|
14
|
+
* What an agent's session sends: the exact text its member approved, in their voice. The key is
|
|
15
|
+
* the runtime's, from the approved call; the session sends no files, buttons or template.
|
|
16
|
+
*/
|
|
17
|
+
export const RuntimeChatSendWire = Schema.Struct({
|
|
18
|
+
chat: ChatPostInput.fields.chat,
|
|
19
|
+
text: ChatPostInput.fields.text,
|
|
20
|
+
reply_to: Schema.optionalKey(Id),
|
|
21
|
+
as: Schema.optionalKey(Schema.Literal("me").annotate({
|
|
22
|
+
description: "me, the member you act for: a session writes in their voice alone.",
|
|
23
|
+
})),
|
|
24
|
+
});
|
|
13
25
|
export const ChatList = Schema.Struct({
|
|
14
26
|
chat: Schema.optionalKey(Id),
|
|
15
27
|
query: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(512))),
|
|
@@ -89,8 +89,8 @@ export declare const ACTION_OPTIONS_ARGUMENT = "_options";
|
|
|
89
89
|
/** The `me` tool's marker: tool calls accept the runtime envelope's chat source. */
|
|
90
90
|
export declare const RUNTIME_SOURCE_META = "segmentstream/runtime-source";
|
|
91
91
|
/**
|
|
92
|
-
* The
|
|
93
|
-
*
|
|
92
|
+
* The exact-post tools' marker: the deployment posts the exact text an agent's member approved to
|
|
93
|
+
* its chat, through `chat_send` with `as: "me"`, or `chat_post_message`, its earlier name.
|
|
94
94
|
*/
|
|
95
95
|
export declare const CHAT_POST_META = "segmentstream/chat-post";
|
|
96
96
|
/**
|
|
@@ -12,7 +12,7 @@ import { ChatSearch } from "../agent/chat-archive.js";
|
|
|
12
12
|
import { declaredChatProviders } from "../chat/providers/index.js";
|
|
13
13
|
import { runtimeAllows } from "./runtime-policy.js";
|
|
14
14
|
import { confirmationFacts, needsConfirmation, withConfirmation, } from "./confirmation.js";
|
|
15
|
-
import { ChatList, ChatListResult, ChatHistory, ChatPostWire, RuntimeChatPostWire, } from "../chat/schemas.js";
|
|
15
|
+
import { ChatList, ChatListResult, ChatHistory, ChatPostWire, RuntimeChatPostWire, RuntimeChatSendWire, } from "../chat/schemas.js";
|
|
16
16
|
import { ChatPostResult } from "../../chat.js";
|
|
17
17
|
import { actionDescription, requires } from "../descriptions.js";
|
|
18
18
|
import { DiscoverInput, DiscoverToolOutput } from "../discovery-schemas.js";
|
|
@@ -268,8 +268,8 @@ export const ACTION_OPTIONS_ARGUMENT = "_options";
|
|
|
268
268
|
/** The `me` tool's marker: tool calls accept the runtime envelope's chat source. */
|
|
269
269
|
export const RUNTIME_SOURCE_META = "segmentstream/runtime-source";
|
|
270
270
|
/**
|
|
271
|
-
* The
|
|
272
|
-
*
|
|
271
|
+
* The exact-post tools' marker: the deployment posts the exact text an agent's member approved to
|
|
272
|
+
* its chat, through `chat_send` with `as: "me"`, or `chat_post_message`, its earlier name.
|
|
273
273
|
*/
|
|
274
274
|
export const CHAT_POST_META = "segmentstream/chat-post";
|
|
275
275
|
const ACTION_OPTIONS_SCHEMA = {
|
|
@@ -799,6 +799,13 @@ export function mcpTools(built, chatHistory = false, storage = {}, navigation =
|
|
|
799
799
|
};
|
|
800
800
|
tools[post] = replacement;
|
|
801
801
|
}
|
|
802
|
+
// An agent's session sends the exact text its member approved through send as me, by the same
|
|
803
|
+
// protocol; a member's own client sends with its own key.
|
|
804
|
+
const send = tools.findIndex((tool) => tool.name === "chat_send");
|
|
805
|
+
if (send >= 0 && declaredChatProviders(manifest.chat).length > 0) {
|
|
806
|
+
const original = tools[send];
|
|
807
|
+
tools[send] = { ...original, _meta: { ...original._meta, [CHAT_POST_META]: 1 } };
|
|
808
|
+
}
|
|
802
809
|
tools.push({
|
|
803
810
|
name: "chat_list",
|
|
804
811
|
title: "List eligible chats",
|
|
@@ -977,6 +984,23 @@ const USER_TOOL_TARGETS = new Set([
|
|
|
977
984
|
"chat-list",
|
|
978
985
|
"chat-history",
|
|
979
986
|
]);
|
|
987
|
+
/**
|
|
988
|
+
* What an agent's session gives an exact-post tool: the approved text alone, whose key the runtime
|
|
989
|
+
* derives from the approved call. Undefined for any other tool or caller.
|
|
990
|
+
*/
|
|
991
|
+
function runtimeChatInput(tool, provenance) {
|
|
992
|
+
if (provenance.kind !== "runtime") {
|
|
993
|
+
return undefined;
|
|
994
|
+
}
|
|
995
|
+
if (tool.name === "chat_send" && tool._meta?.[CHAT_POST_META] === 1) {
|
|
996
|
+
return withConfirmation(encodedJsonSchema(RuntimeChatSendWire), tool.annotations);
|
|
997
|
+
}
|
|
998
|
+
// @legacy ontology.chat-post-message
|
|
999
|
+
if (tool.name === "chat_post_message") {
|
|
1000
|
+
return withConfirmation(encodedJsonSchema(RuntimeChatPostWire), tool.annotations);
|
|
1001
|
+
}
|
|
1002
|
+
return undefined;
|
|
1003
|
+
}
|
|
980
1004
|
/**
|
|
981
1005
|
* The tools a caller may see: those whose every permission the caller's roles grant, each with the
|
|
982
1006
|
* caller's input schema. A guest sees none of the tools only a user has.
|
|
@@ -990,21 +1014,13 @@ export function visibleTools(tools, caller, provenance = { kind: "unverified" })
|
|
|
990
1014
|
return [];
|
|
991
1015
|
}
|
|
992
1016
|
const description = tool.descriptionFor?.(caller) ?? tool.description;
|
|
1017
|
+
const runtime = runtimeChatInput(tool, provenance);
|
|
993
1018
|
if (tool.inputSchemaFor === undefined) {
|
|
994
|
-
return [
|
|
995
|
-
{
|
|
996
|
-
...tool,
|
|
997
|
-
description,
|
|
998
|
-
// @legacy ontology.chat-post-message
|
|
999
|
-
...(tool.name === "chat_post_message" && provenance.kind === "runtime"
|
|
1000
|
-
? {
|
|
1001
|
-
inputSchema: withConfirmation(encodedJsonSchema(RuntimeChatPostWire), tool.annotations),
|
|
1002
|
-
}
|
|
1003
|
-
: {}),
|
|
1004
|
-
},
|
|
1005
|
-
];
|
|
1019
|
+
return [{ ...tool, description, ...(runtime === undefined ? {} : { inputSchema: runtime }) }];
|
|
1006
1020
|
}
|
|
1007
1021
|
const inputSchema = tool.inputSchemaFor(caller);
|
|
1008
|
-
return inputSchema === undefined
|
|
1022
|
+
return inputSchema === undefined
|
|
1023
|
+
? []
|
|
1024
|
+
: [{ ...tool, description, inputSchema: runtime ?? inputSchema }];
|
|
1009
1025
|
});
|
|
1010
1026
|
}
|
|
@@ -14,7 +14,7 @@ import { requireRuntimeOperation } from "./mcp/runtime-policy.js";
|
|
|
14
14
|
import { ChatDelivery } from "../chat.js";
|
|
15
15
|
import { withoutConfirmation } from "./mcp/confirmation.js";
|
|
16
16
|
import { consumeChatEnvelope, CurrentChatCall } from "./chat/envelope.js";
|
|
17
|
-
import { ChatPostWire, ChatSendWire, RuntimeChatPostWire } from "./chat/schemas.js";
|
|
17
|
+
import { ChatPostWire, ChatSendWire, RuntimeChatPostWire, RuntimeChatSendWire, } from "./chat/schemas.js";
|
|
18
18
|
import { OIDC_TOKEN_HEADER } from "./connections.js";
|
|
19
19
|
import { InvalidActionInput, RequestId } from "./errors.js";
|
|
20
20
|
import { recordReads } from "./record-reads.js";
|
|
@@ -233,17 +233,29 @@ function runActionOf(backend, plan, hooks, connections, replicate, chatDelivery)
|
|
|
233
233
|
"for a task whatever its workflow's role grants; the workflow sends what the task wrote.",
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
// The agent's sessions post the exact text their member approved through send as me, or
|
|
237
|
+
// through post_message, its earlier name (@legacy ontology.chat-post-message): the key is
|
|
238
|
+
// the approved call's, never the model's.
|
|
239
|
+
if (planned.name === "agent_chat" &&
|
|
240
|
+
(name === "send" || name === "post_message") &&
|
|
241
|
+
caller.kind === "runtime") {
|
|
242
|
+
const sending = name === "send";
|
|
243
|
+
const values = yield* Schema.decodeUnknownEffect(sending ? RuntimeChatSendWire : RuntimeChatPostWire)(consumed.input, {
|
|
239
244
|
onExcessProperty: "error",
|
|
240
245
|
}).pipe(Effect.mapError(() => new ActionRejected({
|
|
241
|
-
message:
|
|
246
|
+
message: sending
|
|
247
|
+
? "Runtime chat keys are application-owned; only chat, text, reply_to and " +
|
|
248
|
+
'as "me" are accepted.'
|
|
249
|
+
: "Runtime chat keys are application-owned; only chat, text and reply_to are accepted.",
|
|
242
250
|
})));
|
|
243
251
|
if (!envelope?.operation_id) {
|
|
244
252
|
return yield* new ActionRejected({ message: "A confirmed runtime call is required." });
|
|
245
253
|
}
|
|
246
|
-
input = {
|
|
254
|
+
input = {
|
|
255
|
+
...values,
|
|
256
|
+
...(sending ? { as: "me" } : {}),
|
|
257
|
+
idempotency_key: envelope.operation_id,
|
|
258
|
+
};
|
|
247
259
|
}
|
|
248
260
|
// Approving a draft sends it to a person: a member, or the agent acting for one with
|
|
249
261
|
// their confirmation, decides; an agent task has no one to confirm it.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { ActionRejected } from "./errors.js";
|
|
3
|
+
import type { Principal } from "./runtime.js";
|
|
4
|
+
/** Read the member's consented, current workspace IDs during action preparation. A production
|
|
5
|
+
* ontology proves its own identity to the platform. No caller-supplied account or target. */
|
|
6
|
+
export declare const workspaceMemberships: (principal: Principal) => Effect.Effect<{
|
|
7
|
+
readonly consented: boolean;
|
|
8
|
+
readonly workspaceIds: readonly string[];
|
|
9
|
+
}, ActionRejected, import("./runtime.js").OntologyReads>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Effect, Option, Schema } from "effect";
|
|
2
|
+
import { HttpServerRequest } from "effect/unstable/http";
|
|
3
|
+
import { ActionRejected } from "./errors.js";
|
|
4
|
+
import { UserIdentity } from "./user-identity.js";
|
|
5
|
+
const Result = Schema.Struct({
|
|
6
|
+
consented: Schema.Boolean,
|
|
7
|
+
workspaceIds: Schema.Array(Schema.String.check(Schema.isUUID())),
|
|
8
|
+
});
|
|
9
|
+
const empty = { consented: false, workspaceIds: [] };
|
|
10
|
+
/** Read the member's consented, current workspace IDs during action preparation. A production
|
|
11
|
+
* ontology proves its own identity to the platform. No caller-supplied account or target. */
|
|
12
|
+
export const workspaceMemberships = (principal) => Effect.gen(function* () {
|
|
13
|
+
if (principal.kind !== "member") {
|
|
14
|
+
return empty;
|
|
15
|
+
}
|
|
16
|
+
const { configFromEnv } = yield* Effect.promise(() => import("./service/config.js"));
|
|
17
|
+
const config = configFromEnv();
|
|
18
|
+
if (!config.oidc || config.deployment?.target !== "production") {
|
|
19
|
+
return empty;
|
|
20
|
+
}
|
|
21
|
+
const accounts = yield* UserIdentity.find({
|
|
22
|
+
where: {
|
|
23
|
+
userId: principal.id,
|
|
24
|
+
provider: "oidc",
|
|
25
|
+
issuer: config.oidc.issuer,
|
|
26
|
+
revokedAt: null,
|
|
27
|
+
},
|
|
28
|
+
limit: 2,
|
|
29
|
+
});
|
|
30
|
+
if (accounts.length !== 1) {
|
|
31
|
+
return empty;
|
|
32
|
+
}
|
|
33
|
+
const request = yield* Effect.serviceOption(HttpServerRequest.HttpServerRequest);
|
|
34
|
+
const token = (Option.isSome(request) ? request.value.headers["x-vercel-oidc-token"] : undefined) ??
|
|
35
|
+
process.env.VERCEL_OIDC_TOKEN;
|
|
36
|
+
if (!token) {
|
|
37
|
+
return yield* new ActionRejected({ message: "workspace_memberships_unavailable" });
|
|
38
|
+
}
|
|
39
|
+
const url = new URL("/api/internal/v1/workspaces/" +
|
|
40
|
+
encodeURIComponent(config.workspaceId) +
|
|
41
|
+
"/ontology/account/workspaces", config.segmentstreamUrl);
|
|
42
|
+
const clientId = config.oidc.clientId;
|
|
43
|
+
return yield* Effect.tryPromise({
|
|
44
|
+
try: async (signal) => {
|
|
45
|
+
const response = await fetch(url, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
cache: "no-store",
|
|
48
|
+
redirect: "error",
|
|
49
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(15000)]),
|
|
50
|
+
headers: {
|
|
51
|
+
"content-type": "application/json",
|
|
52
|
+
"x-segmentstream-organization-id": config.organizationId,
|
|
53
|
+
"x-segmentstream-runtime-identity": token,
|
|
54
|
+
},
|
|
55
|
+
body: JSON.stringify({ clientId, subject: accounts[0].subject }),
|
|
56
|
+
});
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
throw new Error("Workspace membership request returned HTTP " + response.status);
|
|
59
|
+
}
|
|
60
|
+
return Schema.decodeUnknownSync(Result)(await response.json());
|
|
61
|
+
},
|
|
62
|
+
catch: (cause) => new ActionRejected({ message: "workspace_memberships_unavailable", cause }),
|
|
63
|
+
});
|
|
64
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.192.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",
|