@segmentstream/ontology 0.126.0 → 0.127.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.127.0
|
|
4
|
+
|
|
5
|
+
A `find` MCP tool's `where` takes `{ "$me": [] }`, as a role scope writes `me`, for the caller's
|
|
6
|
+
user ID. Compared with a to-one relationship, bare or with `eq`, `ne` or `in`, it reads the
|
|
7
|
+
relationship's `<relationship>_id` key, so `{ "reporter": { "$me": [] } }` needs no `user:read`;
|
|
8
|
+
anywhere else it is the ID itself, as in `{ "created_by": { "$me": [] } }`. A path from it stays a
|
|
9
|
+
role scope's and is refused. The feedback guidance now finds the member's own items with it in one
|
|
10
|
+
call instead of reading their ID from `me` first, in the ontology's MCP guidance and the agent's
|
|
11
|
+
platform instructions.
|
|
12
|
+
|
|
3
13
|
## 0.126.0
|
|
4
14
|
|
|
5
15
|
A webhook trigger checks any provider's HMAC signature: `signature: { scheme: "hmac", secret,
|
package/dist/app-feedback.js
CHANGED
|
@@ -118,7 +118,7 @@ export const AppFeedback = entity("app_feedback", {
|
|
|
118
118
|
acknowledge: action({
|
|
119
119
|
description: "Record that the member has been told the builders' response to their own feedback, passing " +
|
|
120
120
|
"the responded_at of the response you reported. When they ask about their feedback, find " +
|
|
121
|
-
|
|
121
|
+
'their own items (where {"reporter": {"$me": []}}), tell them what was done, then call ' +
|
|
122
122
|
"this. " +
|
|
123
123
|
"acknowledged is false when there is no such response, as when the builders answered again " +
|
|
124
124
|
"meanwhile: read the item again and report the newer response.",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { OntologyManifest } from "../manifest.js";
|
|
2
|
+
/**
|
|
3
|
+
* `{ "$me": [] }` in the `where` of a find, as a role scope writes the caller: the caller's user id.
|
|
4
|
+
* A to-one relationship compared with it, bare or with `eq`, `ne` or `in`, reads its
|
|
5
|
+
* `<relationship>_id` key (`{ "reporter": { "$me": [] } }` is `{ "reporter_id": "<id>" }`), so the
|
|
6
|
+
* filter reads no `user` record and needs no `user:read`. Any other value it stands in is the id
|
|
7
|
+
* itself, such as `{ "created_by": { "$me": [] } }`. A path from it is a role scope's only: it is
|
|
8
|
+
* refused, since a find compares values, not the sets a path reaches.
|
|
9
|
+
*
|
|
10
|
+
* Runs on the arguments as sent, before the query schema decodes them, and returns a `where`
|
|
11
|
+
* without markers unchanged.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveCallerInWhere(manifest: OntologyManifest, entity: string, where: unknown, callerId: string): {
|
|
14
|
+
readonly where: unknown;
|
|
15
|
+
} | {
|
|
16
|
+
readonly refused: ReadonlyArray<string | number>;
|
|
17
|
+
};
|
|
18
|
+
/** The message of a refused path from `me` in a find. */
|
|
19
|
+
export declare const CALLER_PATH_REFUSED = "A find compares with { \"$me\": [] }, the caller's user id; paths from it are for role scopes.";
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { mePathOf } from "../me.js";
|
|
2
|
+
import { FILTER_OPERATORS, findEntityManifest, MANY_QUANTIFIERS, queryFields, queryLinks, } from "../query.js";
|
|
3
|
+
/**
|
|
4
|
+
* `{ "$me": [] }` in the `where` of a find, as a role scope writes the caller: the caller's user id.
|
|
5
|
+
* A to-one relationship compared with it, bare or with `eq`, `ne` or `in`, reads its
|
|
6
|
+
* `<relationship>_id` key (`{ "reporter": { "$me": [] } }` is `{ "reporter_id": "<id>" }`), so the
|
|
7
|
+
* filter reads no `user` record and needs no `user:read`. Any other value it stands in is the id
|
|
8
|
+
* itself, such as `{ "created_by": { "$me": [] } }`. A path from it is a role scope's only: it is
|
|
9
|
+
* refused, since a find compares values, not the sets a path reaches.
|
|
10
|
+
*
|
|
11
|
+
* Runs on the arguments as sent, before the query schema decodes them, and returns a `where`
|
|
12
|
+
* without markers unchanged.
|
|
13
|
+
*/
|
|
14
|
+
export function resolveCallerInWhere(manifest, entity, where, callerId) {
|
|
15
|
+
if (!holdsMarker(where)) {
|
|
16
|
+
return { where };
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
return { where: resolveWhere(manifest, entity, where, callerId, ["where"]) };
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error instanceof PathRefused) {
|
|
23
|
+
return { refused: error.path };
|
|
24
|
+
}
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** The message of a refused path from `me` in a find. */
|
|
29
|
+
export const CALLER_PATH_REFUSED = 'A find compares with { "$me": [] }, the caller\'s user id; paths from it are for role scopes.';
|
|
30
|
+
class PathRefused extends Error {
|
|
31
|
+
path;
|
|
32
|
+
constructor(path) {
|
|
33
|
+
super(CALLER_PATH_REFUSED);
|
|
34
|
+
this.path = path;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const OPERATORS = new Set(FILTER_OPERATORS);
|
|
38
|
+
const QUANTIFIERS = new Set(MANY_QUANTIFIERS);
|
|
39
|
+
function isPlainObject(value) {
|
|
40
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41
|
+
}
|
|
42
|
+
function holdsMarker(value) {
|
|
43
|
+
if (mePathOf(value) !== undefined) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
return value.some(holdsMarker);
|
|
48
|
+
}
|
|
49
|
+
return isPlainObject(value) && Object.values(value).some(holdsMarker);
|
|
50
|
+
}
|
|
51
|
+
/** A bare `me` or an object of operators comparing with it: what a key field takes. */
|
|
52
|
+
function comparesCaller(condition) {
|
|
53
|
+
if (mePathOf(condition) !== undefined) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return (isPlainObject(condition) &&
|
|
57
|
+
Object.keys(condition).length > 0 &&
|
|
58
|
+
Object.keys(condition).every((key) => OPERATORS.has(key)) &&
|
|
59
|
+
holdsMarker(condition));
|
|
60
|
+
}
|
|
61
|
+
function resolveValue(value, callerId, path) {
|
|
62
|
+
const hops = mePathOf(value);
|
|
63
|
+
if (hops !== undefined) {
|
|
64
|
+
if (hops.length > 0) {
|
|
65
|
+
throw new PathRefused(path);
|
|
66
|
+
}
|
|
67
|
+
return callerId;
|
|
68
|
+
}
|
|
69
|
+
if (Array.isArray(value)) {
|
|
70
|
+
return value.map((item, index) => resolveValue(item, callerId, [...path, index]));
|
|
71
|
+
}
|
|
72
|
+
if (isPlainObject(value)) {
|
|
73
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
74
|
+
key,
|
|
75
|
+
resolveValue(item, callerId, [...path, key]),
|
|
76
|
+
]));
|
|
77
|
+
}
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
function resolveWhere(manifest, entityName, where, callerId, path) {
|
|
81
|
+
const entity = findEntityManifest(manifest, entityName);
|
|
82
|
+
if (entity === undefined || !isPlainObject(where) || mePathOf(where) !== undefined) {
|
|
83
|
+
return where;
|
|
84
|
+
}
|
|
85
|
+
const keys = new Set(queryFields(entity).map((field) => field.name));
|
|
86
|
+
const links = new Map(queryLinks(manifest, entityName, true).map((link) => [link.name, link]));
|
|
87
|
+
const entries = [];
|
|
88
|
+
for (const [key, condition] of Object.entries(where)) {
|
|
89
|
+
const at = [...path, key];
|
|
90
|
+
const link = links.get(key);
|
|
91
|
+
if ((key === "and" || key === "or") && Array.isArray(condition)) {
|
|
92
|
+
entries.push([
|
|
93
|
+
key,
|
|
94
|
+
condition.map((sub, index) => resolveWhere(manifest, entityName, sub, callerId, [...at, index])),
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
else if (key === "not") {
|
|
98
|
+
entries.push([key, resolveWhere(manifest, entityName, condition, callerId, at)]);
|
|
99
|
+
}
|
|
100
|
+
else if (link === undefined || !holdsMarker(condition)) {
|
|
101
|
+
entries.push([key, resolveValue(condition, callerId, at)]);
|
|
102
|
+
}
|
|
103
|
+
else if (link.cardinality === "one" && keys.has(`${key}_id`) && comparesCaller(condition)) {
|
|
104
|
+
entries.push([`${key}_id`, resolveValue(condition, callerId, at)]);
|
|
105
|
+
}
|
|
106
|
+
else if (link.cardinality === "many" &&
|
|
107
|
+
isPlainObject(condition) &&
|
|
108
|
+
Object.keys(condition).every((quantifier) => QUANTIFIERS.has(quantifier))) {
|
|
109
|
+
entries.push([
|
|
110
|
+
key,
|
|
111
|
+
Object.fromEntries(Object.entries(condition).map(([quantifier, sub]) => [
|
|
112
|
+
quantifier,
|
|
113
|
+
resolveWhere(manifest, link.target, sub, callerId, [...at, quantifier]),
|
|
114
|
+
])),
|
|
115
|
+
]);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
entries.push([key, resolveWhere(manifest, link.target, condition, callerId, at)]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const names = entries.map(([key]) => key);
|
|
122
|
+
// `{ reporter: me, reporter_id: … }` names the key twice: both conditions must hold.
|
|
123
|
+
return new Set(names).size === names.length
|
|
124
|
+
? Object.fromEntries(entries)
|
|
125
|
+
: { and: entries.map(([key, condition]) => ({ [key]: condition })) };
|
|
126
|
+
}
|
|
@@ -52,7 +52,8 @@ export const FIND_CONDITIONS = "where: a field takes a bare value (eq), null (is
|
|
|
52
52
|
"dates and timestamps also gt, gte, lt, lte and between [from, to], which includes both ends. " +
|
|
53
53
|
"ne also matches empty values. Dates are YYYY-MM-DD. A relationship takes conditions on its " +
|
|
54
54
|
"target's fields, one level deep; a to-many one wraps them in some, none or every. and and or " +
|
|
55
|
-
|
|
55
|
+
'take lists of conditions; not takes one. {"$me": []} is the caller\'s user id, also for a ' +
|
|
56
|
+
'to-one relationship: {"owner": {"$me": []}}. Unknown fields and operators are refused.';
|
|
56
57
|
// Clients that shorten schema descriptions keep this first sentence.
|
|
57
58
|
const WHERE_DESCRIPTION = "Operators: eq, ne, in, is_null; text contains, starts_with; ordered gt, gte, lt, lte, " +
|
|
58
59
|
"between. All conditions must hold; the tool description has the rules.";
|
|
@@ -8,6 +8,7 @@ import { encodeManifest } from "../../manifest.js";
|
|
|
8
8
|
import { describeError, SCOPE_MISMATCH } from "../metric-query-platform.js";
|
|
9
9
|
import { gatewayCredential, gatewayDecisions } from "../decisions.js";
|
|
10
10
|
import { CurrentPrincipal, withPrincipal } from "../authentication.js";
|
|
11
|
+
import { CALLER_PATH_REFUSED, resolveCallerInWhere } from "../caller-where.js";
|
|
11
12
|
import { currentCaller } from "../caller-context.js";
|
|
12
13
|
import { requireRuntimeOperation, runtimeManifest } from "./runtime-policy.js";
|
|
13
14
|
import { CONFIRMATION_PREVIEW_METHOD, previewLocale, withoutConfirmation } from "./confirmation.js";
|
|
@@ -427,7 +428,13 @@ function runTool(server, tool, args, request, preview) {
|
|
|
427
428
|
return structured(yield* chats.history(yield* decodeArguments(ChatHistory, args), identityToken(request)));
|
|
428
429
|
case "find": {
|
|
429
430
|
const schemas = built.schemas.get(target.planned.name);
|
|
430
|
-
const
|
|
431
|
+
const resolved = resolveCallerInWhere(built.plan.ontology.manifest, target.planned.name, args.where, (yield* CurrentPrincipal).id);
|
|
432
|
+
if ("refused" in resolved) {
|
|
433
|
+
return yield* new InvalidArguments({
|
|
434
|
+
issues: [{ path: resolved.refused, message: CALLER_PATH_REFUSED }],
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
const query = (yield* decodeArguments(schemas.query, args.where === undefined ? args : { ...args, where: resolved.where }));
|
|
431
438
|
const page = yield* operations.find(target.planned, toQuery(query));
|
|
432
439
|
return structured(yield* encoded(schemas.findResult, page));
|
|
433
440
|
}
|
|
@@ -627,8 +634,8 @@ export const FEEDBACK_INSTRUCTIONS = "Feedback: this app accepts feedback for it
|
|
|
627
634
|
"something works badly or asks for something new. Do not offer what you can do yourself; offer " +
|
|
628
635
|
"once per problem. Before submitting, look for the user's open app_feedback with the same " +
|
|
629
636
|
"subject. Submit with app_feedback_submit only after the user agrees to the title and summary you " +
|
|
630
|
-
"show in their language. When the user asks about their feedback, read only their own
|
|
631
|
-
|
|
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 ' +
|
|
632
639
|
"them the builders' response, then call app_feedback_acknowledge with its responded_at.";
|
|
633
640
|
export const AUTOMATIC_FAILURE_REPORT_INSTRUCTIONS = "Feedback: During requested work, this workspace preauthorizes minimal technical failure reports. " +
|
|
634
641
|
"Automatically record unexpected or persistent tool/connection failures through app_feedback_submit; " +
|
|
@@ -638,7 +645,7 @@ export const AUTOMATIC_FAILURE_REPORT_INSTRUCTIONS = "Feedback: During requested
|
|
|
638
645
|
"and never claim it was recorded before a successful submission or existing-item read. " +
|
|
639
646
|
"Feature/change requests and sharing task contents or files still require the member's agreement " +
|
|
640
647
|
"to the title and summary. Asked about their feedback, read only the caller's own items " +
|
|
641
|
-
"
|
|
648
|
+
'(where {"reporter": {"$me": []}}) and acknowledge only the response you relayed.';
|
|
642
649
|
/**
|
|
643
650
|
* Fixed guidance keeps initialization independent of ontology size: the feedback paragraph depends
|
|
644
651
|
* only on whether the caller may run `app_feedback_submit`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.127.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",
|