@segmentstream/ontology 0.131.1 → 0.134.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.
@@ -0,0 +1,37 @@
1
+ export const FEEDBACK_SUBMIT_TOOL = "app_feedback_submit";
2
+ export const FEEDBACK_ATTACH_TOOL = "app_feedback_file_attach";
3
+ const PURPOSE = "Feedback reaches the app's builders through app_feedback_submit: something no permitted tool, " +
4
+ "field or data provides, an operation refused for lack of permission, an operation that fails " +
5
+ "unexpectedly or a retryable failure that persists, or something the member says works badly or " +
6
+ "wants new. Do not send what you can do yourself; raise each problem once, and first reuse the " +
7
+ "member's open app_feedback with the same subject.";
8
+ const ASK_FIRST = "Offer it, and submit only after the member agrees to the title and summary you show them in " +
9
+ "their language.";
10
+ const AUTOMATIC = "During requested work, this workspace preauthorizes minimal technical failure reports: record " +
11
+ "an unexpected or persistent tool or connection failure without asking, with only the operation, " +
12
+ "a safe technical reason and the request_id or error code, never business contents, credentials " +
13
+ "or files. Then explain the actual reason and that the report was recorded, in one or two " +
14
+ "sentences, rather than offering to report it. A feature or change request, or sharing task " +
15
+ "contents or files, still needs the member's agreement to the title and summary you show them in " +
16
+ "their language.";
17
+ const RECORDED = "Never say feedback was recorded before a successful submission or a read of the existing item.";
18
+ const FILES = "Attach a screenshot or file with app_feedback_file_attach only when the member agreed to share it.";
19
+ const READ_OWN = "When the member asks about their feedback, read only their own, since builders can read " +
20
+ 'everyone\'s: app_feedback_find with where {"reporter": {"$me": []}}. Tell them the builders\' ' +
21
+ "response, then call app_feedback_acknowledge with its responded_at; acknowledge only a response " +
22
+ "you told them.";
23
+ /**
24
+ * How an agent handles app feedback, stated once for every client of the ontology: the MCP server's
25
+ * instructions carry it for a caller who may submit, and `app_feedback_submit`'s description carries
26
+ * it for clients that read tools rather than server instructions, such as the workspace agent. It is
27
+ * platform guidance for the model; the agent words what it tells the member in the chat's language.
28
+ */
29
+ export function feedbackGuidance(policy) {
30
+ return [
31
+ PURPOSE,
32
+ policy.automaticFailureReports ? AUTOMATIC : ASK_FIRST,
33
+ RECORDED,
34
+ ...(policy.files ? [FILES] : []),
35
+ READ_OWN,
36
+ ].join(" ");
37
+ }
@@ -18,12 +18,6 @@ export declare const MCP_PATH = "/mcp";
18
18
  /** The MCP revisions the server speaks, newest first. */
19
19
  export declare const MCP_PROTOCOL_VERSIONS: readonly ["2025-11-25", "2025-06-18"];
20
20
  export declare const MCP_STREAM_MAX_DURATION_MS = 45000;
21
- /**
22
- * When to offer feedback, for a caller who may send it. Platform guidance for the agent; the agent
23
- * words the offer itself, in the chat's language.
24
- */
25
- export declare const FEEDBACK_INSTRUCTIONS: string;
26
- export declare const AUTOMATIC_FAILURE_REPORT_INSTRUCTIONS: string;
27
21
  export interface McpServerOptions {
28
22
  readonly navigation?: PageCatalogV1;
29
23
  readonly appOrigins?: readonly string[] | undefined;
@@ -39,6 +39,7 @@ import { uploadFields } from "../../storage/attachments.js";
39
39
  import { RECORDS_OR_METRIC_QUERIES } from "../../render.js";
40
40
  import { memberFileOperations } from "../member-files.js";
41
41
  import { ACTION_OPTIONS_ARGUMENT, mcpTools, RUNTIME_SOURCE_META, visibleTools, } from "./tools.js";
42
+ import { FEEDBACK_ATTACH_TOOL, FEEDBACK_SUBMIT_TOOL, feedbackGuidance, } from "./feedback-guidance.js";
42
43
  import { listTools, toolDefinition } from "./listing.js";
43
44
  /** The URL path of the ontology's MCP server, outside `/api/ontology`: one per app. */
44
45
  export const MCP_PATH = "/mcp";
@@ -624,28 +625,6 @@ function readResource({ built, tools }, uri) {
624
625
  }
625
626
  });
626
627
  }
627
- /**
628
- * When to offer feedback, for a caller who may send it. Platform guidance for the agent; the agent
629
- * words the offer itself, in the chat's language.
630
- */
631
- export const FEEDBACK_INSTRUCTIONS = "Feedback: this app accepts feedback for its builders. Offer to send it when the user wants " +
632
- "something no permitted tool, field or data provides, an operation is refused for lack of " +
633
- "permission, an operation fails unexpectedly or a retryable failure persists, or the user says " +
634
- "something works badly or asks for something new. Do not offer what you can do yourself; offer " +
635
- "once per problem. Before submitting, look for the user's open app_feedback with the same " +
636
- "subject. Submit with app_feedback_submit only after the user agrees to the title and summary you " +
637
- "show in their language. When the user asks about their feedback, read only their own, since " +
638
- 'builders can read everyone\'s: app_feedback_find with where {"reporter": {"$me": []}}. Tell ' +
639
- "them the builders' response, then call app_feedback_acknowledge with its responded_at.";
640
- export const AUTOMATIC_FAILURE_REPORT_INSTRUCTIONS = "Feedback: During requested work, this workspace preauthorizes minimal technical failure reports. " +
641
- "Automatically record unexpected or persistent tool/connection failures through app_feedback_submit; " +
642
- "first reuse the caller's open report with the same subject. Include only the operation, safe technical " +
643
- "reason and request_id/error code, never business contents, credentials or files. Explain the actual " +
644
- "reason and that the report was recorded in one or two sentences; do not merely offer to report it, " +
645
- "and never claim it was recorded before a successful submission or existing-item read. " +
646
- "Feature/change requests and sharing task contents or files still require the member's agreement " +
647
- "to the title and summary. Asked about their feedback, read only the caller's own items " +
648
- '(where {"reporter": {"$me": []}}) and acknowledge only the response you relayed.';
649
628
  /**
650
629
  * Fixed guidance keeps initialization independent of ontology size: the feedback paragraph depends
651
630
  * only on whether the caller may run `app_feedback_submit`.
@@ -672,14 +651,7 @@ function instructions(feedback, files, automaticFailureReports, byMeaning, metri
672
651
  "external actions (openWorldHint) require confirmation before preparation; idempotence " +
673
652
  "alone does not waive it. Present confirmations in the chat's language using " +
674
653
  "action, entity, field and option labels and readable record titles, never tool names, ids or JSON.",
675
- ...(feedback
676
- ? [
677
- (automaticFailureReports
678
- ? AUTOMATIC_FAILURE_REPORT_INSTRUCTIONS
679
- : FEEDBACK_INSTRUCTIONS) +
680
- (files ? " Add each screenshot or file with app_feedback_file_attach." : ""),
681
- ]
682
- : []),
654
+ ...(feedback ? [`Feedback: ${feedbackGuidance({ automaticFailureReports, files })}`] : []),
683
655
  ].join("\n\n");
684
656
  }
685
657
  function negotiate(requested) {
@@ -709,7 +681,7 @@ function dispatch(server, message, request) {
709
681
  title: "Ontology",
710
682
  version: server.built.plan.ontology.manifest.hash,
711
683
  },
712
- instructions: instructions(visibleTools(server.tools, principal, caller).some((tool) => tool.name === "app_feedback_submit"), visibleTools(server.tools, principal, caller).some((tool) => tool.name === "app_feedback_file_attach"), server.built.plan.ontology.manifest.feedback?.automaticFailureReports === true, server.built.plan.ontology.config.discovery !== undefined, visibleTools(server.tools, principal, caller).some((tool) => tool.name === "query_metrics")),
684
+ instructions: instructions(visibleTools(server.tools, principal, caller).some((tool) => tool.name === FEEDBACK_SUBMIT_TOOL), visibleTools(server.tools, principal, caller).some((tool) => tool.name === FEEDBACK_ATTACH_TOOL), server.built.plan.ontology.manifest.feedback?.automaticFailureReports === true, server.built.plan.ontology.config.discovery !== undefined, visibleTools(server.tools, principal, caller).some((tool) => tool.name === "query_metrics")),
713
685
  });
714
686
  case "ping":
715
687
  return rpcResult(id, {});
@@ -18,6 +18,7 @@ import { actionDescription, requires } from "../descriptions.js";
18
18
  import { DiscoverInput, DiscoverToolOutput } from "../discovery-schemas.js";
19
19
  import { DIMENSIONS_LIMIT, hasMetrics, VALUES_DEFAULT, VALUES_LIMIT } from "./metric-tools.js";
20
20
  import { isReadScoped } from "../toolsets.js";
21
+ import { FEEDBACK_ATTACH_TOOL, FEEDBACK_SUBMIT_TOOL, feedbackGuidance, } from "./feedback-guidance.js";
21
22
  import { NavigationInput, NavigationToolOutput } from "../navigation-schemas.js";
22
23
  import { METRIC_QUERY_FILTER_OPERATORS, METRIC_QUERY_GRANULARITIES, METRIC_QUERY_LIMITS, METRIC_QUERY_PERIOD_UNITS, METRIC_QUERY_PERIODS, HistoryPage, MAXIMUM_TIMEZONE_LENGTH, Me, } from "../schemas.js";
23
24
  const DEFS = "#/$defs/";
@@ -748,6 +749,19 @@ export function mcpTools(built, chatHistory = false, storage = {}, navigation =
748
749
  for (const toolset of built.plan.ontology.toolsets ?? []) {
749
750
  tools.push(...toolset.tools.map((tool) => toolsetTool(toolset, tool)));
750
751
  }
752
+ const submit = tools.findIndex((tool) => tool.name === FEEDBACK_SUBMIT_TOOL);
753
+ // Clients that read tools rather than the server's instructions, such as the workspace agent, learn
754
+ // the workspace's feedback policy where they learn the tool.
755
+ if (submit >= 0) {
756
+ const guidance = feedbackGuidance({
757
+ automaticFailureReports: manifest.feedback?.automaticFailureReports === true,
758
+ files: tools.some((tool) => tool.name === FEEDBACK_ATTACH_TOOL),
759
+ });
760
+ tools[submit] = {
761
+ ...tools[submit],
762
+ description: `${tools[submit].description}\n\n${guidance}`,
763
+ };
764
+ }
751
765
  const discover = tools.findIndex((tool) => tool.name === "discover");
752
766
  // Word search duplicates the client's own tool search; ranking by meaning does not.
753
767
  if (discover >= 0) {
@@ -252,9 +252,9 @@ function runActionOf(backend, plan, hooks, connections, replicate, chatDelivery)
252
252
  });
253
253
  }
254
254
  const requestId = yield* RequestId;
255
- const delivery = (planned.name === "agent_chat" &&
256
- (name === "post_message" || name === "preview_message")) ||
257
- (planned.name === "agent_review" && name === "approve")
255
+ // Every action of the chat registry and of held replies reaches chats through the service:
256
+ // posts, takeovers, imports, approvals and redrafts.
257
+ const delivery = planned.name === "agent_chat" || planned.name === "agent_review"
258
258
  ? chatDelivery?.({
259
259
  backend,
260
260
  principal,
@@ -463,7 +463,9 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
463
463
  readonly origins: Schema.$Array<Schema.String>;
464
464
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
465
465
  readonly scheme: Schema.String;
466
- readonly secret: Schema.String;
466
+ readonly connection: Schema.optionalKey<Schema.String>;
467
+ readonly input: Schema.optionalKey<Schema.String>;
468
+ readonly secret: Schema.optionalKey<Schema.String>;
467
469
  }>>;
468
470
  readonly confirmations: Schema.optionalKey<Schema.Boolean>;
469
471
  }>, {
@@ -823,7 +825,9 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
823
825
  readonly origins: Schema.$Array<Schema.String>;
824
826
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
825
827
  readonly scheme: Schema.String;
826
- readonly secret: Schema.String;
828
+ readonly connection: Schema.optionalKey<Schema.String>;
829
+ readonly input: Schema.optionalKey<Schema.String>;
830
+ readonly secret: Schema.optionalKey<Schema.String>;
827
831
  }>>;
828
832
  readonly confirmations: Schema.optionalKey<Schema.Boolean>;
829
833
  }>, {
@@ -23,6 +23,7 @@ import { platformChatArchive } from "./agent/chat-archive.js";
23
23
  import { archiveRoutes } from "./agent/archive-routes.js";
24
24
  import { makeChatDelivery } from "./chat/delivery.js";
25
25
  import { platformDeliveryArchive } from "./chat/archive.js";
26
+ import { platformHistoryArchive } from "./chat/history-import.js";
26
27
  import { chatRoutes } from "./chat/routes.js";
27
28
  import { agentLayer } from "./agent/server.js";
28
29
  import { agentTasksLayer } from "./agent/tasks.js";
@@ -348,7 +349,7 @@ export function createOntologyService(ontology, config) {
348
349
  {
349
350
  origin: config.agentOrigin,
350
351
  ...(config.agentTaskTransport === undefined ? {} : { fetch: config.agentTaskTransport }),
351
- });
352
+ }, config.chatHistoryArchive ?? platformHistoryArchive(config));
352
353
  const chatHistory = config.runtimeIdentity === undefined ? undefined : platformChatArchive(config);
353
354
  const metricQueries = makeMetricQueries({
354
355
  ontology,
package/dist/sign-in.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { AnyConnectionHandle } from "./connection.js";
1
2
  /**
2
3
  * Who may become a member by signing in. `invited`: only a person whose email a member row already
3
4
  * holds, created by an invitation or a role grant; anyone else is refused. `open`: anyone who signs
@@ -77,8 +78,9 @@ export interface GuestOptions<P = unknown> {
77
78
  /**
78
79
  * A bot check before a guest exists: the website shows a challenge, and a new guest's agent token
79
80
  * is issued only for a token from it that the challenge's provider accepts. `scheme` names the
80
- * provider; `secret` names the workspace secret holding the provider's secret key, which only the
81
- * platform reads. Absent, no challenge is asked for.
81
+ * provider; `connection` and `input` the connection's verification value holding the provider's
82
+ * secret key, such as a `TurnstileConnection`'s `secret_key`, which only the platform reads.
83
+ * Absent, no challenge is asked for.
82
84
  */
83
85
  readonly botCheck?: GuestBotCheck;
84
86
  /**
@@ -89,23 +91,44 @@ export interface GuestOptions<P = unknown> {
89
91
  }
90
92
  /**
91
93
  * The challenge providers a guest's bot check can verify. `turnstile` is Cloudflare Turnstile: the
92
- * website renders its widget with the site key, and the workspace secret holds its secret key.
94
+ * website renders its widget with the site key, and a connection holds its secret key.
93
95
  */
94
96
  export declare const GUEST_BOT_CHECK_SCHEMES: readonly ["turnstile"];
95
97
  export type GuestBotCheckScheme = (typeof GUEST_BOT_CHECK_SCHEMES)[number];
96
98
  export declare function isGuestBotCheckScheme(value: unknown): value is GuestBotCheckScheme;
97
99
  /** The challenge a website's visitor passes before they become a guest. */
98
- export interface GuestBotCheck {
100
+ export type GuestBotCheck = {
99
101
  readonly scheme: GuestBotCheckScheme;
100
- /** The workspace secret holding the provider's secret key, such as `turnstile-secret-key`. */
102
+ /** The connection holding the provider's secret key, listed in `defineOntology({ connections })`. */
103
+ readonly connection: AnyConnectionHandle;
104
+ /** Its verification value, such as a `TurnstileConnection`'s `secret_key`. */
105
+ readonly input: string;
106
+ readonly secret?: undefined;
107
+ } | {
108
+ readonly scheme: GuestBotCheckScheme;
109
+ /** The workspace secret holding the provider's secret key: the older form. */
101
110
  readonly secret: string;
102
- }
111
+ readonly connection?: undefined;
112
+ readonly input?: undefined;
113
+ };
114
+ /** A bot check as the manifest carries it: the connection by its key. */
115
+ export type ResolvedGuestBotCheck = {
116
+ readonly scheme: GuestBotCheckScheme;
117
+ readonly connection: string;
118
+ readonly input: string;
119
+ readonly secret?: undefined;
120
+ } | {
121
+ readonly scheme: GuestBotCheckScheme;
122
+ readonly secret: string;
123
+ readonly connection?: undefined;
124
+ readonly input?: undefined;
125
+ };
103
126
  /** Guests as the manifest carries them; the built-in role `guest` holds their permissions. */
104
127
  export interface ResolvedGuest {
105
128
  readonly channels: ReadonlyArray<GuestChannel>;
106
129
  readonly origins: ReadonlyArray<string>;
107
130
  /** The challenge a new guest passes, when declared. */
108
- readonly botCheck?: GuestBotCheck;
131
+ readonly botCheck?: ResolvedGuestBotCheck;
109
132
  /** Present when guests may confirm actions that need a confirmation. */
110
133
  readonly confirmations?: true;
111
134
  }
package/dist/sign-in.js CHANGED
@@ -30,7 +30,7 @@ export function isGuestChannel(value) {
30
30
  }
31
31
  /**
32
32
  * The challenge providers a guest's bot check can verify. `turnstile` is Cloudflare Turnstile: the
33
- * website renders its widget with the site key, and the workspace secret holds its secret key.
33
+ * website renders its widget with the site key, and a connection holds its secret key.
34
34
  */
35
35
  export const GUEST_BOT_CHECK_SCHEMES = ["turnstile"];
36
36
  export function isGuestBotCheckScheme(value) {
@@ -29,7 +29,7 @@ export declare const UserIdentity: import("./entity.js").DraftEntity<"user_ident
29
29
  readonly subject: import("./property.js").Property<string, false, false>;
30
30
  readonly username: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
31
31
  readonly display: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
32
- readonly origin: import("./property.js").Property<"link" | "invite" | "attach" | "sign_in" | "channel" | "pairing", false, false>;
32
+ readonly origin: import("./property.js").Property<"link" | "invite" | "attach" | "channel" | "sign_in" | "pairing", false, false>;
33
33
  readonly revokedAt: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
34
34
  readonly accountKey: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, true>>;
35
35
  readonly memberKey: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, true>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.131.1",
3
+ "version": "0.134.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",