@segmentstream/ontology 0.191.0 → 0.192.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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.192.1
4
+
5
+ Show the originating chat title in private persona notices and render a labeled settings link as a native channel button.
6
+
7
+ ## 0.192.0
8
+
9
+ 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.
10
+
3
11
  ## 0.191.0
4
12
 
5
13
  `chat_send` is now an agent session's exact-post tool, as `chat_post_message` has been. Where the
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: `prepare` with connections and only with them, except for built-in actions,
1505
- * and `prepare` or `handler` always.
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";
@@ -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;
@@ -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
+ }
@@ -1005,7 +1005,7 @@ export function agentLayer(options) {
1005
1005
  return json({ chat: null });
1006
1006
  }
1007
1007
  const id = String(chat.id);
1008
- return json({ chat: (yield* claim(id, memberId)) ? id : null });
1008
+ return json((yield* claim(id, memberId)) ? { chat: id, title: chat.title } : { chat: null });
1009
1009
  })));
1010
1010
  }
1011
1011
  if (store.readChatPersona !== undefined) {
@@ -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.191.0",
3
+ "version": "0.192.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",