@segmentstream/ontology 0.120.0 → 0.122.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 +36 -0
- package/README.md +55 -38
- package/dist/analyze.d.ts +11 -5
- package/dist/analyze.js +79 -34
- package/dist/chat.d.ts +2 -1
- package/dist/diagnostics.d.ts +3 -3
- package/dist/diagnostics.js +1 -0
- package/dist/feedback-config.d.ts +10 -1
- package/dist/feedback-config.js +46 -20
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/manifest.d.ts +29 -9
- package/dist/manifest.js +12 -5
- package/dist/permissions.d.ts +1 -1
- package/dist/permissions.js +1 -1
- package/dist/role.d.ts +22 -3
- package/dist/role.js +42 -6
- package/dist/runtime/agents.js +58 -0
- package/dist/runtime/generated-actions.js +14 -4
- package/dist/runtime/member-writes.d.ts +10 -4
- package/dist/runtime/member-writes.js +15 -7
- package/dist/runtime/model.d.ts +5 -0
- package/dist/runtime/model.js +5 -2
- package/dist/runtime/new-user-hook.js +7 -4
- package/dist/runtime/principals.d.ts +30 -10
- package/dist/runtime/principals.js +88 -44
- package/dist/runtime/records.js +1 -1
- package/dist/runtime/resolve-agent-identity.js +3 -3
- package/dist/runtime/sql-runtime.js +2 -1
- package/dist/runtime/user-roles.d.ts +8 -7
- package/dist/runtime/user-roles.js +17 -12
- package/dist/runtime/where.js +4 -4
- package/dist/service/agent/chat-archive.d.ts +2 -1
- package/dist/service/agent/chat-archive.js +12 -8
- package/dist/service/agent/server.js +1 -0
- package/dist/service/agent/tasks.d.ts +2 -0
- package/dist/service/agent/tasks.js +7 -4
- package/dist/service/agent/web-tokens.js +9 -1
- package/dist/service/chat/reads.js +5 -1
- package/dist/service/mcp/tools.js +7 -3
- package/dist/service/runtime-contract.d.ts +12 -0
- package/dist/service/service.js +2 -0
- package/dist/storage/authorization.js +9 -6
- package/dist/workflow.d.ts +7 -3
- package/package.json +1 -1
package/dist/diagnostics.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
-
export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
|
|
2
|
+
export declare const DIAGNOSTIC_CODES: readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"];
|
|
3
3
|
export type DiagnosticCode = (typeof DIAGNOSTIC_CODES)[number];
|
|
4
4
|
/** A problem `check` found in an ontology definition. */
|
|
5
5
|
export declare const Diagnostic: Schema.Struct<{
|
|
6
6
|
readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
|
|
7
|
-
readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
|
|
7
|
+
readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
|
|
8
8
|
/** Where the problem is, for example `lead.properties.status.options[1]`. */
|
|
9
9
|
readonly path: Schema.String;
|
|
10
10
|
readonly message: Schema.String;
|
|
@@ -14,7 +14,7 @@ declare const InvalidOntology_base: Schema.Class<InvalidOntology, Schema.TaggedS
|
|
|
14
14
|
readonly message: Schema.String;
|
|
15
15
|
readonly diagnostics: Schema.$Array<Schema.Struct<{
|
|
16
16
|
readonly severity: Schema.Literals<readonly ["error", "warning", "info"]>;
|
|
17
|
-
readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
|
|
17
|
+
readonly code: Schema.Literals<readonly ["invalid-source", "missing-column", "invalid-column", "invalid-scope", "invalid-scope-path", "scope-reads-all", "scope-unused", "scope-member-overlap", "source-with-actions", "source-with-index", "invalid-metric", "unknown-metric", "circular-metric", "invalid-join", "missing-join", "invalid-entity", "invalid-property", "invalid-relationship", "invalid-actions", "invalid-action", "invalid-action-input", "invalid-role", "invalid-name", "reserved-name", "duplicate-name", "invalid-entity-id", "duplicate-entity-id", "missing-label", "missing-description", "invalid-title", "invalid-options", "invalid-default", "invalid-constraint", "unknown-relationship-target", "inverse-collision", "invalid-on-delete", "invalid-phrase", "invalid-index", "unknown-reference", "invalid-renamed-from", "earlier-name", "invalid-guide", "invalid-writes", "generated-update-empty", "managed-without-effect", "missing-permissions", "invalid-permission", "unknown-permission", "removed-allow", "unreachable-action", "wildcard-permission", "invalid-sign-in", "invalid-inbox", "invalid-connection", "invalid-feedback", "invalid-discovery", "invalid-email", "feedback-unanswerable", "feedback-unreportable", "agent-tools-implicit", "unknown-connection", "unused-connection", "invalid-prepare", "invalid-tool-name", "invalid-toolset", "toolset-lock-mismatch", "invalid-alignment", "single-entity-model-metric", "invalid-workflow", "workflow_role_unknown", "workflow_role_is_member", "workflow_role_grants_nothing", "workflow_role_wildcard", "workflow_role_scoped", "workflow_cron_never_fires", "workflow_input_invalid", "workflow_cron_invalid", "workflow_run_missing", "invalid-trigger", "trigger_action_unknown", "trigger_function_async", "trigger_runs_invalid", "workflow_trigger_limit_exceeded", "workflow_webhook_duplicate", "workflow_webhook_input_invalid", "workflow_webhook_mixed_triggers", "workflow_webhook_signature_invalid", "workflow_webhook_verification_invalid", "workflow_webhook_headers_invalid", "workflow_webhook_limit_exceeded"]>;
|
|
18
18
|
/** Where the problem is, for example `lead.properties.status.options[1]`. */
|
|
19
19
|
readonly path: Schema.String;
|
|
20
20
|
readonly message: Schema.String;
|
package/dist/diagnostics.js
CHANGED
|
@@ -15,10 +15,19 @@ export interface ResolvedFeedback {
|
|
|
15
15
|
type Report = (code: Diagnostic["code"], path: string, message: string, severity?: Diagnostic["severity"]) => void;
|
|
16
16
|
/** Validate the declaration without consulting storage or any other provider. */
|
|
17
17
|
export declare function feedbackOptions(value: unknown, report: Report): FeedbackOptions | boolean;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Add the builders' grants to the workspace's roles, and, while the ontology keeps the implicit
|
|
20
|
+
* `member`, the implicit reporter role people hold beside it. Without the implicit `member`, the
|
|
21
|
+
* workspace's own roles grant `app_feedback:submit` and reading and acknowledging one's own items.
|
|
22
|
+
*/
|
|
19
23
|
export declare function feedbackRoles(options: FeedbackOptions | boolean, files: boolean, roles: ReadonlyArray<Role>, report: Report): {
|
|
20
24
|
readonly feedback: ResolvedFeedback;
|
|
21
25
|
readonly roles: ReadonlyArray<Role>;
|
|
22
26
|
};
|
|
23
27
|
export declare function checkFeedbackResponders(roles: ReadonlyArray<Role>, report: Report): void;
|
|
28
|
+
/**
|
|
29
|
+
* Without the implicit reporter, the workspace's roles say who may report: warn when feedback is on
|
|
30
|
+
* and no role grants `app_feedback:submit`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function checkFeedbackReporters(roles: ReadonlyArray<Role>, report: Report): void;
|
|
24
33
|
export {};
|
package/dist/feedback-config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nameToWire } from "./authoring-names.js";
|
|
2
|
-
import { FEEDBACK_REPORTER_ROLE
|
|
2
|
+
import { FEEDBACK_REPORTER_ROLE } from "./names.js";
|
|
3
3
|
import { isAllowed, normalizePermission } from "./permissions.js";
|
|
4
|
-
import { isRole, role, roleEntries } from "./role.js";
|
|
4
|
+
import { implicitMemberOf, implicitRole, isImplicitRole, isRole, role, roleEntries, } from "./role.js";
|
|
5
5
|
/** Validate the declaration without consulting storage or any other provider. */
|
|
6
6
|
export function feedbackOptions(value, report) {
|
|
7
7
|
if (value === undefined) {
|
|
@@ -39,16 +39,22 @@ export function feedbackOptions(value, report) {
|
|
|
39
39
|
...(Array.isArray(options.builders) ? { builders: options.builders } : {}),
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Add the builders' grants to the workspace's roles, and, while the ontology keeps the implicit
|
|
44
|
+
* `member`, the implicit reporter role people hold beside it. Without the implicit `member`, the
|
|
45
|
+
* workspace's own roles grant `app_feedback:submit` and reading and acknowledging one's own items.
|
|
46
|
+
*/
|
|
43
47
|
export function feedbackRoles(options, files, roles, report) {
|
|
44
48
|
if (options === false) {
|
|
45
49
|
return { feedback: { enabled: false, files: false, builders: [] }, roles };
|
|
46
50
|
}
|
|
47
51
|
const configured = typeof options === "object" ? options.builders : undefined;
|
|
48
52
|
const builders = new Set();
|
|
53
|
+
// @legacy ontology.implicit-member
|
|
54
|
+
const implicit = implicitMemberOf(roles);
|
|
49
55
|
if (configured === undefined) {
|
|
50
56
|
for (const candidate of roles) {
|
|
51
|
-
if (candidate
|
|
57
|
+
if (!isImplicitRole(candidate) &&
|
|
52
58
|
Array.isArray(candidate.permissions) &&
|
|
53
59
|
candidate.permissions.some((permission) => ["user:grant_roles", "user:*"].includes(normalizePermission(permission)))) {
|
|
54
60
|
builders.add(candidate.name);
|
|
@@ -63,10 +69,11 @@ export function feedbackRoles(options, files, roles, report) {
|
|
|
63
69
|
? nameToWire(candidate.name)
|
|
64
70
|
: undefined;
|
|
65
71
|
if (name === undefined ||
|
|
66
|
-
name ===
|
|
67
|
-
name === FEEDBACK_REPORTER_ROLE
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
!roles.some((declared) => declared.name === name && !isImplicitRole(declared)) ||
|
|
73
|
+
(implicit !== undefined && name === FEEDBACK_REPORTER_ROLE)) {
|
|
74
|
+
report("invalid-feedback", `feedback.builders[${index}]`, implicit === undefined
|
|
75
|
+
? "A builder must name a declared role."
|
|
76
|
+
: "A builder must name a declared role other than member or feedback_reporter.");
|
|
70
77
|
}
|
|
71
78
|
else {
|
|
72
79
|
builders.add(name);
|
|
@@ -94,7 +101,11 @@ export function feedbackRoles(options, files, roles, report) {
|
|
|
94
101
|
});
|
|
95
102
|
});
|
|
96
103
|
const own = { reporter: { $me: [] } };
|
|
97
|
-
|
|
104
|
+
// @legacy ontology.implicit-member
|
|
105
|
+
if (implicit === undefined) {
|
|
106
|
+
return { feedback: resolvedFeedback(options, files, builders), roles: resolved };
|
|
107
|
+
}
|
|
108
|
+
resolved.push(implicitRole(role(FEEDBACK_REPORTER_ROLE, {
|
|
98
109
|
description: "Implicit feedback authority of authenticated human members; never assigned.",
|
|
99
110
|
permissions: [
|
|
100
111
|
"app_feedback:submit",
|
|
@@ -107,21 +118,22 @@ export function feedbackRoles(options, files, roles, report) {
|
|
|
107
118
|
]
|
|
108
119
|
: []),
|
|
109
120
|
],
|
|
110
|
-
}));
|
|
121
|
+
})));
|
|
122
|
+
return { feedback: resolvedFeedback(options, files, builders), roles: resolved };
|
|
123
|
+
}
|
|
124
|
+
function resolvedFeedback(options, files, builders) {
|
|
111
125
|
return {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
: {}),
|
|
119
|
-
},
|
|
120
|
-
roles: resolved,
|
|
126
|
+
enabled: true,
|
|
127
|
+
files,
|
|
128
|
+
builders: [...builders],
|
|
129
|
+
...(typeof options === "object" && options.automaticFailureReports === true
|
|
130
|
+
? { automaticFailureReports: true }
|
|
131
|
+
: {}),
|
|
121
132
|
};
|
|
122
133
|
}
|
|
123
134
|
export function checkFeedbackResponders(roles, report) {
|
|
124
|
-
|
|
135
|
+
// @legacy ontology.implicit-member
|
|
136
|
+
const member = implicitMemberOf(roles);
|
|
125
137
|
if (!roles.some((candidate) => {
|
|
126
138
|
const permissions = [
|
|
127
139
|
...(Array.isArray(member?.permissions) ? member.permissions : []),
|
|
@@ -133,3 +145,17 @@ export function checkFeedbackResponders(roles, report) {
|
|
|
133
145
|
report("feedback-unanswerable", "feedback.builders", "No effective role can read and answer feedback. Configure feedback: { builders: [...] }.", "warning");
|
|
134
146
|
}
|
|
135
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Without the implicit reporter, the workspace's roles say who may report: warn when feedback is on
|
|
150
|
+
* and no role grants `app_feedback:submit`.
|
|
151
|
+
*/
|
|
152
|
+
export function checkFeedbackReporters(roles, report) {
|
|
153
|
+
if (roles.some((candidate) => isAllowed("app_feedback:submit", {
|
|
154
|
+
permissions: Array.isArray(candidate.permissions) ? candidate.permissions : [],
|
|
155
|
+
}))) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
report("feedback-unreportable", "feedback", "No role grants app_feedback:submit, so nobody can report feedback. Grant it, with " +
|
|
159
|
+
"app_feedback:read and app_feedback:acknowledge scoped to { reporter: me }, to the roles " +
|
|
160
|
+
"that may report, or set feedback: false.", "warning");
|
|
161
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ export { ON_DELETE, rel } from "./relationship.js";
|
|
|
41
41
|
export type { AnyRelationship, EntityTarget, LazyEntity, ManyOptions, ManyRelationship, OnDelete, OneOptions, OneRelationship, Phrase, } from "./relationship.js";
|
|
42
42
|
export { renderCatalog } from "./render.js";
|
|
43
43
|
export type { RenderOptions } from "./render.js";
|
|
44
|
-
export { member, role, roleEntries, rolePermissions } from "./role.js";
|
|
44
|
+
export { implicitMemberOf, implicitRoleNames, isImplicitRole, member, role, roleEntries, rolePermissions, } from "./role.js";
|
|
45
45
|
export type { Role, RoleOptions, RolePermission } from "./role.js";
|
|
46
46
|
export type { FeedbackOptions, ResolvedFeedback } from "./feedback-config.js";
|
|
47
47
|
export { after, changed, cron, cronNeverFires, cronProblem, isWorkflow, isWorkflowTrigger, MAX_ACTION_TRIGGERS, MAX_WORKFLOWS, nextCronTime, webhook, workflow, } from "./workflow.js";
|
|
@@ -75,8 +75,8 @@ export type { GeneratedActionManifest, GeneratedActions } from "./runtime/genera
|
|
|
75
75
|
export { Change, Edit, EditKind, HistoryEntry } from "./runtime/history.js";
|
|
76
76
|
export { ActionOutcome, ActionValidation, findAction, PREPARE_TIMEOUT, resolveAction, runAction, } from "./runtime/pipeline.js";
|
|
77
77
|
export type { ActionRequest, AfterCommit, CommittedAction, FoundAction, } from "./runtime/pipeline.js";
|
|
78
|
-
export { API_KEY_ITERATIONS, API_KEY_PREFIX, checkSignIn, createApiKey, createServiceUser, findApiKey, generateApiKey, grantMemberRoles, hashApiKeySecret, listApiKeys, listMembers, countUsersWithoutEmailIdentity, countUsersWithoutSegmentStreamIdentity, MEMBER_HISTORY_ACTIONS, parseApiKey, principalsOntology, resolveApiKeyCredential, resolvePrincipalByApiKey, resolvePrincipalByIdentity, reconcileWorkflowUsers, resolveWorkflowUser, revokeApiKey, WORKFLOW_USER_PROVIDER, workflowSubject, revokeMemberRoles, setMemberActive, setMemberBlocked, revokeMemberSessions, setUserRoles, SIGN_IN_RECORD_INTERVAL_MS, updateMemberRoles, } from "./runtime/principals.js";
|
|
79
|
-
export type { ApiKeyCredential, ApiKeyParts, ApiKeySummary, CreatedApiKey, IdentityClaims, MemberKey, MemberRolesChange, MemberStatus, MemberSummary, PrincipalsManifest, } from "./runtime/principals.js";
|
|
78
|
+
export { API_KEY_ITERATIONS, API_KEY_PREFIX, checkSignIn, createApiKey, createServiceUser, findApiKey, generateApiKey, grantMemberRoles, hashApiKeySecret, implicitRoleNamesOf, listApiKeys, listMembers, countUsersWithoutEmailIdentity, countUsersWithoutSegmentStreamIdentity, MEMBER_HISTORY_ACTIONS, parseApiKey, principalsOntology, resolveApiKeyCredential, resolvePrincipalByApiKey, resolvePrincipalByIdentity, reconcileWorkflowUsers, resolveWorkflowUser, revokeApiKey, WORKFLOW_USER_PROVIDER, workflowSubject, revokeMemberRoles, setMemberActive, setMemberBlocked, revokeMemberSessions, setUserRoles, SIGN_IN_RECORD_INTERVAL_MS, updateMemberRoles, workflowRoles, } from "./runtime/principals.js";
|
|
79
|
+
export type { ApiKeyCredential, ApiKeyParts, ApiKeySummary, CreatedApiKey, IdentityClaims, MemberKey, MemberRolesChange, MemberStatus, MemberSummary, PrincipalsManifest, StoredRolesListing, } from "./runtime/principals.js";
|
|
80
80
|
export { backendLayer, postgresLayer, sqlServiceRuntime } from "./runtime/service-binding.js";
|
|
81
81
|
export { makeOntologyRuntime } from "./runtime/sql-runtime.js";
|
|
82
82
|
export type { SqlOntologyRuntime, WriteScope } from "./runtime/sql-runtime.js";
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ export { AGENT_TOOL_VERBS, agentToolPermission, agentToolsOf, DEFAULT_MEMBER_PER
|
|
|
23
23
|
export { p, PROPERTY_TYPES, propertyDefinition } from "./property.js";
|
|
24
24
|
export { ON_DELETE, rel } from "./relationship.js";
|
|
25
25
|
export { renderCatalog } from "./render.js";
|
|
26
|
-
export { member, role, roleEntries, rolePermissions } from "./role.js";
|
|
26
|
+
export { implicitMemberOf, implicitRoleNames, isImplicitRole, member, role, roleEntries, rolePermissions, } from "./role.js";
|
|
27
27
|
export { after, changed, cron, cronNeverFires, cronProblem, isWorkflow, isWorkflowTrigger, MAX_ACTION_TRIGGERS, MAX_WORKFLOWS, nextCronTime, webhook, workflow, } from "./workflow.js";
|
|
28
28
|
export { MAX_WEBHOOK_BODY_BYTES, MAX_META_WEBHOOK_BODY_BYTES, MAX_WEBHOOK_HEADERS, MAX_WEBHOOKS, WEBHOOK_BASE_PATH, WEBHOOK_SIGNATURE_SCHEMES, webhookDelivery, webhookHeaderProblem, webhookPath, } from "./webhooks.js";
|
|
29
29
|
export { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, SIGN_IN_METHODS, SIGN_IN_POLICIES, SIGN_UP_CHANNELS, GUEST_BOT_CHECK_SCHEMES, GUEST_CHANNELS, matchesWebsite,
|
|
@@ -46,7 +46,7 @@ export { InvalidQuery, InvalidValues, MemberNotFound, PrincipalRejected, StoredR
|
|
|
46
46
|
export { generatedActionManifests, generatedActions, upsertActionName, } from "./runtime/generated-actions.js";
|
|
47
47
|
export { Change, Edit, EditKind, HistoryEntry } from "./runtime/history.js";
|
|
48
48
|
export { ActionOutcome, ActionValidation, findAction, PREPARE_TIMEOUT, resolveAction, runAction, } from "./runtime/pipeline.js";
|
|
49
|
-
export { API_KEY_ITERATIONS, API_KEY_PREFIX, checkSignIn, createApiKey, createServiceUser, findApiKey, generateApiKey, grantMemberRoles, hashApiKeySecret, listApiKeys, listMembers, countUsersWithoutEmailIdentity, countUsersWithoutSegmentStreamIdentity, MEMBER_HISTORY_ACTIONS, parseApiKey, principalsOntology, resolveApiKeyCredential, resolvePrincipalByApiKey, resolvePrincipalByIdentity, reconcileWorkflowUsers, resolveWorkflowUser, revokeApiKey, WORKFLOW_USER_PROVIDER, workflowSubject, revokeMemberRoles, setMemberActive, setMemberBlocked, revokeMemberSessions, setUserRoles, SIGN_IN_RECORD_INTERVAL_MS, updateMemberRoles, } from "./runtime/principals.js";
|
|
49
|
+
export { API_KEY_ITERATIONS, API_KEY_PREFIX, checkSignIn, createApiKey, createServiceUser, findApiKey, generateApiKey, grantMemberRoles, hashApiKeySecret, implicitRoleNamesOf, listApiKeys, listMembers, countUsersWithoutEmailIdentity, countUsersWithoutSegmentStreamIdentity, MEMBER_HISTORY_ACTIONS, parseApiKey, principalsOntology, resolveApiKeyCredential, resolvePrincipalByApiKey, resolvePrincipalByIdentity, reconcileWorkflowUsers, resolveWorkflowUser, revokeApiKey, WORKFLOW_USER_PROVIDER, workflowSubject, revokeMemberRoles, setMemberActive, setMemberBlocked, revokeMemberSessions, setUserRoles, SIGN_IN_RECORD_INTERVAL_MS, updateMemberRoles, workflowRoles, } from "./runtime/principals.js";
|
|
50
50
|
export { backendLayer, postgresLayer, sqlServiceRuntime } from "./runtime/service-binding.js";
|
|
51
51
|
export { makeOntologyRuntime } from "./runtime/sql-runtime.js";
|
|
52
52
|
// The HTTP service derived from the ontology.
|
package/dist/manifest.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { CHAT_KINDS } from "./chat-channel.js";
|
|
|
3
3
|
import { Effect, Schema } from "effect";
|
|
4
4
|
import type { ResolvedConnection, ResolvedEntity } from "./analyze.js";
|
|
5
5
|
import type { ResolvedFeedback } from "./feedback-config.js";
|
|
6
|
-
import type
|
|
6
|
+
import { type Role } from "./role.js";
|
|
7
7
|
import type { ResolvedToolset } from "./toolset.js";
|
|
8
8
|
import { type ResolvedGuest, type ResolvedSignInOptions, type SignInPolicy } from "./sign-in.js";
|
|
9
9
|
/**
|
|
@@ -413,10 +413,15 @@ export type ScopeManifest = typeof ScopeManifest.Type;
|
|
|
413
413
|
export declare const RoleManifest: Schema.Struct<{
|
|
414
414
|
readonly name: Schema.String;
|
|
415
415
|
readonly description: Schema.String;
|
|
416
|
+
/**
|
|
417
|
+
* Whether the platform built the role in rather than the workspace declaring it: the guests' role,
|
|
418
|
+
* and the implicit `member` and `feedback_reporter` of an ontology declaring `member`. A role the
|
|
419
|
+
* workspace names `member` is not built in.
|
|
420
|
+
*/
|
|
416
421
|
readonly builtIn: Schema.Boolean;
|
|
417
422
|
/**
|
|
418
|
-
* What the role may do, wildcards included; for the built-in `member`, what every
|
|
419
|
-
* may do. Always written; absent from version 1 manifests.
|
|
423
|
+
* What the role may do, wildcards included; for the built-in `member`, what every invited or
|
|
424
|
+
* paired user may do. Always written; absent from version 1 manifests.
|
|
420
425
|
*/
|
|
421
426
|
readonly permissions: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
422
427
|
/**
|
|
@@ -1012,10 +1017,15 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
|
|
|
1012
1017
|
readonly roles: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
|
|
1013
1018
|
readonly name: Schema.String;
|
|
1014
1019
|
readonly description: Schema.String;
|
|
1020
|
+
/**
|
|
1021
|
+
* Whether the platform built the role in rather than the workspace declaring it: the guests' role,
|
|
1022
|
+
* and the implicit `member` and `feedback_reporter` of an ontology declaring `member`. A role the
|
|
1023
|
+
* workspace names `member` is not built in.
|
|
1024
|
+
*/
|
|
1015
1025
|
readonly builtIn: Schema.Boolean;
|
|
1016
1026
|
/**
|
|
1017
|
-
* What the role may do, wildcards included; for the built-in `member`, what every
|
|
1018
|
-
* may do. Always written; absent from version 1 manifests.
|
|
1027
|
+
* What the role may do, wildcards included; for the built-in `member`, what every invited or
|
|
1028
|
+
* paired user may do. Always written; absent from version 1 manifests.
|
|
1019
1029
|
*/
|
|
1020
1030
|
readonly permissions: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
1021
1031
|
/**
|
|
@@ -2719,10 +2729,15 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
2719
2729
|
readonly roles: Schema.$Array<Schema.encodeKeys<Schema.Struct<{
|
|
2720
2730
|
readonly name: Schema.String;
|
|
2721
2731
|
readonly description: Schema.String;
|
|
2732
|
+
/**
|
|
2733
|
+
* Whether the platform built the role in rather than the workspace declaring it: the guests' role,
|
|
2734
|
+
* and the implicit `member` and `feedback_reporter` of an ontology declaring `member`. A role the
|
|
2735
|
+
* workspace names `member` is not built in.
|
|
2736
|
+
*/
|
|
2722
2737
|
readonly builtIn: Schema.Boolean;
|
|
2723
2738
|
/**
|
|
2724
|
-
* What the role may do, wildcards included; for the built-in `member`, what every
|
|
2725
|
-
* may do. Always written; absent from version 1 manifests.
|
|
2739
|
+
* What the role may do, wildcards included; for the built-in `member`, what every invited or
|
|
2740
|
+
* paired user may do. Always written; absent from version 1 manifests.
|
|
2726
2741
|
*/
|
|
2727
2742
|
readonly permissions: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
2728
2743
|
/**
|
|
@@ -3163,10 +3178,15 @@ export declare const OntologyManifest: Schema.declareConstructor<{
|
|
|
3163
3178
|
readonly roles: Schema.$Array<Schema.Struct<{
|
|
3164
3179
|
readonly name: Schema.String;
|
|
3165
3180
|
readonly description: Schema.String;
|
|
3181
|
+
/**
|
|
3182
|
+
* Whether the platform built the role in rather than the workspace declaring it: the guests' role,
|
|
3183
|
+
* and the implicit `member` and `feedback_reporter` of an ontology declaring `member`. A role the
|
|
3184
|
+
* workspace names `member` is not built in.
|
|
3185
|
+
*/
|
|
3166
3186
|
readonly builtIn: Schema.Boolean;
|
|
3167
3187
|
/**
|
|
3168
|
-
* What the role may do, wildcards included; for the built-in `member`, what every
|
|
3169
|
-
* may do. Always written; absent from version 1 manifests.
|
|
3188
|
+
* What the role may do, wildcards included; for the built-in `member`, what every invited or
|
|
3189
|
+
* paired user may do. Always written; absent from version 1 manifests.
|
|
3170
3190
|
*/
|
|
3171
3191
|
readonly permissions: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
3172
3192
|
/**
|
package/dist/manifest.js
CHANGED
|
@@ -2,9 +2,10 @@ import { CHAT_CHANNEL_NAME, CHAT_KINDS } from "./chat-channel.js";
|
|
|
2
2
|
import { balancesOf, metricExpression } from "./metric.js";
|
|
3
3
|
import { Effect, Schema, SchemaTransformation } from "effect";
|
|
4
4
|
import { acceptingEarlierManifestNames, withEarlierManifestNames } from "./legacy.js";
|
|
5
|
-
import { humanize,
|
|
5
|
+
import { humanize, GUEST_ROLE } from "./names.js";
|
|
6
6
|
import { PROPERTY_TYPES } from "./property.js";
|
|
7
7
|
import { ON_DELETE } from "./relationship.js";
|
|
8
|
+
import { isImplicitRole } from "./role.js";
|
|
8
9
|
import { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, isGuestBotCheckScheme, isGuestChannel, isSignInPolicy, isSignUpChannel, websiteOrigin, } from "./sign-in.js";
|
|
9
10
|
/**
|
|
10
11
|
* The manifest format this SDK writes. Readers accept any version and ignore unknown fields. Version
|
|
@@ -289,10 +290,15 @@ export const ScopeManifest = Schema.Struct({
|
|
|
289
290
|
export const RoleManifest = Schema.Struct({
|
|
290
291
|
name: Schema.String,
|
|
291
292
|
description: Schema.String,
|
|
293
|
+
/**
|
|
294
|
+
* Whether the platform built the role in rather than the workspace declaring it: the guests' role,
|
|
295
|
+
* and the implicit `member` and `feedback_reporter` of an ontology declaring `member`. A role the
|
|
296
|
+
* workspace names `member` is not built in.
|
|
297
|
+
*/
|
|
292
298
|
builtIn: Schema.Boolean,
|
|
293
299
|
/**
|
|
294
|
-
* What the role may do, wildcards included; for the built-in `member`, what every
|
|
295
|
-
* may do. Always written; absent from version 1 manifests.
|
|
300
|
+
* What the role may do, wildcards included; for the built-in `member`, what every invited or
|
|
301
|
+
* paired user may do. Always written; absent from version 1 manifests.
|
|
296
302
|
*/
|
|
297
303
|
permissions: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
298
304
|
/**
|
|
@@ -935,8 +941,9 @@ export function buildManifest(input) {
|
|
|
935
941
|
roles: input.roles.map((candidate) => ({
|
|
936
942
|
name: candidate.name,
|
|
937
943
|
description: candidate.description,
|
|
938
|
-
|
|
939
|
-
|
|
944
|
+
// @legacy ontology.implicit-member
|
|
945
|
+
// The implicit `member` and reporter are built in only while the ontology declares `member`.
|
|
946
|
+
builtIn: isImplicitRole(candidate) ||
|
|
940
947
|
(candidate.name === GUEST_ROLE && input.signIn.guest !== undefined),
|
|
941
948
|
permissions: [...candidate.permissions],
|
|
942
949
|
...((candidate.scopes ?? []).length > 0
|
package/dist/permissions.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ export type UserIdentityVerb = (typeof USER_IDENTITY_VERBS)[number];
|
|
|
85
85
|
export declare const WILDCARD_ENTITY_VERBS: ReadonlyMap<string, ReadonlySet<string>>;
|
|
86
86
|
/** Whether a wildcard entity covers this verb of this entity, both in snake_case. */
|
|
87
87
|
export declare function wildcardEntityCovers(entity: string, verb: string): boolean;
|
|
88
|
-
/** What the
|
|
88
|
+
/** What the deprecated `member` export grants: reading everything. */
|
|
89
89
|
export declare const DEFAULT_MEMBER_PERMISSIONS: ReadonlyArray<string>;
|
|
90
90
|
export interface ParsedPermission {
|
|
91
91
|
/** An entity name, or `*`. */
|
package/dist/permissions.js
CHANGED
|
@@ -107,7 +107,7 @@ export function wildcardEntityCovers(entity, verb) {
|
|
|
107
107
|
const verbs = WILDCARD_ENTITY_VERBS.get(entity);
|
|
108
108
|
return verbs === undefined || verbs.has(verb);
|
|
109
109
|
}
|
|
110
|
-
/** What the
|
|
110
|
+
/** What the deprecated `member` export grants: reading everything. */
|
|
111
111
|
export const DEFAULT_MEMBER_PERMISSIONS = [`${WILDCARD}:${READ_VERB}`];
|
|
112
112
|
/** `<entity>:<verb>` with lowercase snake_case entities and lowercase snake_case verbs, or `*` for either. */
|
|
113
113
|
const PERMISSION = /^(\*|[a-z][a-zA-Z0-9]*(?:_[a-z0-9]+)*):(\*|[a-z][a-zA-Z0-9]*(?:_[a-z0-9]+)*)$/;
|
package/dist/role.d.ts
CHANGED
|
@@ -53,9 +53,28 @@ export declare function rolePermissions(entries: ReadonlyArray<RolePermission>):
|
|
|
53
53
|
export declare function roleEntries(permissions: ReadonlyArray<string>, scopes: ReadonlyArray<ScopedPermission>): ReadonlyArray<RolePermission>;
|
|
54
54
|
export declare function role<const Name extends string>(name: Name, options: RoleOptions): Role<Name>;
|
|
55
55
|
export declare function isRole(value: unknown): value is Role;
|
|
56
|
+
/** A role the platform builds in while the ontology keeps the implicit `member`. */
|
|
57
|
+
export declare function implicitRole<Candidate extends Role>(candidate: Candidate): Candidate;
|
|
58
|
+
/** Whether the platform built this role in, rather than the workspace declaring it. */
|
|
59
|
+
export declare function isImplicitRole(candidate: Role): boolean;
|
|
56
60
|
/**
|
|
57
|
-
* The built-in
|
|
58
|
-
*
|
|
59
|
-
|
|
61
|
+
* The built-in `member` every invited or paired user, workflow and agent task holds, while the
|
|
62
|
+
* ontology declares `defineOntology({ member })`; `undefined` once it does not.
|
|
63
|
+
*/
|
|
64
|
+
export declare function implicitMemberOf(roles: ReadonlyArray<Role>): Role | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Whether a role name is reserved: `member` and `feedback_reporter`, only while the ontology keeps
|
|
67
|
+
* the implicit `member`. Stored assignments of a reserved name grant nothing and are never written.
|
|
68
|
+
*/
|
|
69
|
+
export declare function isReservedRoleName(roles: ReadonlyArray<Role>, name: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The role names reserved while the ontology keeps the implicit `member`: `member` and
|
|
72
|
+
* `feedback_reporter`. Without it, none: a stored assignment of either is a role like any other.
|
|
73
|
+
*/
|
|
74
|
+
export declare function implicitRoleNames(roles: ReadonlyArray<Role>): ReadonlyArray<string>;
|
|
75
|
+
/**
|
|
76
|
+
* The earlier built-in role with its default permissions, `*:read`, which an ontology declaring
|
|
77
|
+
* `defineOntology({ member })` lists. An ontology without `member` declares roles of its own, such
|
|
78
|
+
* as `role("team", { … })`, instead.
|
|
60
79
|
*/
|
|
61
80
|
export declare const member: Role<"member">;
|
package/dist/role.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MEMBER_ROLE } from "./names.js";
|
|
1
|
+
import { FEEDBACK_REPORTER_ROLE, MEMBER_ROLE, toSnakeCase } from "./names.js";
|
|
2
2
|
import { DEFAULT_MEMBER_PERMISSIONS, normalizePermission, } from "./permissions.js";
|
|
3
3
|
export const RoleTypeId = Symbol.for("@segmentstream/ontology/Role");
|
|
4
4
|
function isScoped(value) {
|
|
@@ -65,12 +65,48 @@ export function role(name, options) {
|
|
|
65
65
|
export function isRole(value) {
|
|
66
66
|
return typeof value === "object" && value !== null && RoleTypeId in value;
|
|
67
67
|
}
|
|
68
|
+
// @legacy ontology.implicit-member
|
|
69
|
+
// The roles held without being granted: the built-in `member` an ontology declaring
|
|
70
|
+
// `defineOntology({ member })` keeps, and people's feedback reporter beside it. An ontology without
|
|
71
|
+
// `member` builds in no role, and `member` and `feedback_reporter` are names like any other.
|
|
72
|
+
// The mark is a symbol property, so a copy of the role, `{ ...role, permissions }`, keeps it.
|
|
73
|
+
const ImplicitRoleId = Symbol.for("@segmentstream/ontology/ImplicitRole");
|
|
74
|
+
/** A role the platform builds in while the ontology keeps the implicit `member`. */
|
|
75
|
+
export function implicitRole(candidate) {
|
|
76
|
+
return { ...candidate, [ImplicitRoleId]: true };
|
|
77
|
+
}
|
|
78
|
+
/** Whether the platform built this role in, rather than the workspace declaring it. */
|
|
79
|
+
export function isImplicitRole(candidate) {
|
|
80
|
+
return candidate[ImplicitRoleId] === true;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The built-in `member` every invited or paired user, workflow and agent task holds, while the
|
|
84
|
+
* ontology declares `defineOntology({ member })`; `undefined` once it does not.
|
|
85
|
+
*/
|
|
86
|
+
export function implicitMemberOf(roles) {
|
|
87
|
+
return roles.find((candidate) => candidate.name === MEMBER_ROLE && isImplicitRole(candidate));
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether a role name is reserved: `member` and `feedback_reporter`, only while the ontology keeps
|
|
91
|
+
* the implicit `member`. Stored assignments of a reserved name grant nothing and are never written.
|
|
92
|
+
*/
|
|
93
|
+
export function isReservedRoleName(roles, name) {
|
|
94
|
+
return (implicitMemberOf(roles) !== undefined &&
|
|
95
|
+
(name === MEMBER_ROLE || toSnakeCase(name) === FEEDBACK_REPORTER_ROLE));
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The role names reserved while the ontology keeps the implicit `member`: `member` and
|
|
99
|
+
* `feedback_reporter`. Without it, none: a stored assignment of either is a role like any other.
|
|
100
|
+
*/
|
|
101
|
+
export function implicitRoleNames(roles) {
|
|
102
|
+
return implicitMemberOf(roles) === undefined ? [] : [MEMBER_ROLE, FEEDBACK_REPORTER_ROLE];
|
|
103
|
+
}
|
|
68
104
|
/**
|
|
69
|
-
* The built-in role
|
|
70
|
-
*
|
|
71
|
-
*
|
|
105
|
+
* The earlier built-in role with its default permissions, `*:read`, which an ontology declaring
|
|
106
|
+
* `defineOntology({ member })` lists. An ontology without `member` declares roles of its own, such
|
|
107
|
+
* as `role("team", { … })`, instead.
|
|
72
108
|
*/
|
|
73
|
-
export const member = role(MEMBER_ROLE, {
|
|
109
|
+
export const member = implicitRole(role(MEMBER_ROLE, {
|
|
74
110
|
description: "Every active app user.",
|
|
75
111
|
permissions: DEFAULT_MEMBER_PERMISSIONS,
|
|
76
|
-
});
|
|
112
|
+
}));
|
package/dist/runtime/agents.js
CHANGED
|
@@ -7,6 +7,7 @@ import { chatChannelKind } from "../chat-channel.js";
|
|
|
7
7
|
import { AgentReview } from "../agent-review.js";
|
|
8
8
|
import { AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, CHANNEL_USERS_TABLE, IDENTITY_NOTICES_TABLE, USER_TABLE, } from "../migrate/storage.js";
|
|
9
9
|
import { inboxRolesOf } from "../manifest.js";
|
|
10
|
+
import { GUEST_ROLE } from "../names.js";
|
|
10
11
|
import { MAX_QUERY_LIMIT } from "../query.js";
|
|
11
12
|
import { beginReplicationWrite } from "../replication/transaction.js";
|
|
12
13
|
import { IdentityInUse, } from "../service/runtime-contract.js";
|
|
@@ -15,6 +16,7 @@ import { resolveAgentIdentity } from "./resolve-agent-identity.js";
|
|
|
15
16
|
import { completeAgentLimitNotice } from "./agent-counters.js";
|
|
16
17
|
import { isMemberBlocked, setMemberBlocked, resolveMemberById } from "./principals.js";
|
|
17
18
|
import { sqlAgentWebStore } from "./agent-web.js";
|
|
19
|
+
import { guestChat } from "./guests.js";
|
|
18
20
|
import { WEB_PROVIDER } from "../service/runtime-identity.js";
|
|
19
21
|
import { isRecordId } from "./records.js";
|
|
20
22
|
import { makeOntologyRuntime } from "./sql-runtime.js";
|
|
@@ -548,6 +550,62 @@ export function sqlAgentStore(ontology, sql) {
|
|
|
548
550
|
};
|
|
549
551
|
}));
|
|
550
552
|
}).pipe(Effect.orDie),
|
|
553
|
+
seeGuestChat: (guestId) => Effect.gen(function* () {
|
|
554
|
+
// Only the visitors' chats of an inbox that takes the guests.
|
|
555
|
+
if (!isRecordId(guestId) || !inboxRolesOf(ontology.manifest).has(GUEST_ROLE)) {
|
|
556
|
+
return undefined;
|
|
557
|
+
}
|
|
558
|
+
const externalId = guestChat(guestId);
|
|
559
|
+
return yield* sql.withTransaction(Effect.gen(function* () {
|
|
560
|
+
yield* beginReplicationWrite(sql);
|
|
561
|
+
// Turns of one visitor run one after the other: the first creates it, the rest find it.
|
|
562
|
+
yield* rows(`SELECT pg_advisory_xact_lock(hashtext($1))`, [
|
|
563
|
+
`chat:${WEB_PROVIDER}:${externalId}`,
|
|
564
|
+
]);
|
|
565
|
+
const runtime = makeOntologyRuntime(ontology, sql, {
|
|
566
|
+
action: `${AgentChat.name}.seen`,
|
|
567
|
+
actionId: randomUUID(),
|
|
568
|
+
principalId: null,
|
|
569
|
+
});
|
|
570
|
+
const [found] = yield* runtime.find({
|
|
571
|
+
entity: AgentChat.name,
|
|
572
|
+
options: {
|
|
573
|
+
where: { provider: WEB_PROVIDER, external_id: externalId },
|
|
574
|
+
limit: 1,
|
|
575
|
+
forUpdate: true,
|
|
576
|
+
},
|
|
577
|
+
});
|
|
578
|
+
if (found !== undefined && found.kind !== "private") {
|
|
579
|
+
return undefined;
|
|
580
|
+
}
|
|
581
|
+
const now = new Date();
|
|
582
|
+
// A visitor has no name: the chat is titled by its key, as the archive keeps it.
|
|
583
|
+
const chat = found === undefined
|
|
584
|
+
? yield* runtime.create({
|
|
585
|
+
entity: AgentChat.name,
|
|
586
|
+
values: {
|
|
587
|
+
provider: WEB_PROVIDER,
|
|
588
|
+
external_id: externalId,
|
|
589
|
+
kind: "private",
|
|
590
|
+
title: externalId,
|
|
591
|
+
last_message_at: now.toISOString(),
|
|
592
|
+
},
|
|
593
|
+
})
|
|
594
|
+
: messageDue(found.last_message_at, now)
|
|
595
|
+
? yield* runtime.update({
|
|
596
|
+
entity: AgentChat.name,
|
|
597
|
+
id: String(found.id),
|
|
598
|
+
values: { last_message_at: now.toISOString() },
|
|
599
|
+
})
|
|
600
|
+
: found;
|
|
601
|
+
return {
|
|
602
|
+
id: String(chat.id),
|
|
603
|
+
title: String(chat.title),
|
|
604
|
+
purpose: nullableText(chat.purpose),
|
|
605
|
+
whenToUse: nullableText(chat.when_to_use),
|
|
606
|
+
};
|
|
607
|
+
}));
|
|
608
|
+
}).pipe(Effect.orDie),
|
|
551
609
|
holdReply: (input) => sql
|
|
552
610
|
.withTransaction(Effect.gen(function* () {
|
|
553
611
|
if (!isRecordId(input.memberId)) {
|
|
@@ -2,6 +2,7 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { uploadInput, BLOB_UPLOAD_ANNOTATION } from "../blob.js";
|
|
3
3
|
import { action } from "../action.js";
|
|
4
4
|
import { GENERATED_UPSERT_PREFIX, MEMBER_ROLE } from "../names.js";
|
|
5
|
+
import { implicitMemberOf, implicitRoleNames } from "../role.js";
|
|
5
6
|
import { generatedActionPermissions } from "../permissions.js";
|
|
6
7
|
import { p, REFERENCE_ANNOTATION } from "../property.js";
|
|
7
8
|
import { isCalendarDate, isInstant } from "../query.js";
|
|
@@ -138,13 +139,22 @@ export function writesOnlyThroughActions(ontology, entityName, actionName) {
|
|
|
138
139
|
}
|
|
139
140
|
/** A role a member may be granted: one the ontology declares, never the implicit `member`. */
|
|
140
141
|
function grantableRole(ontology) {
|
|
141
|
-
const declared = userRoleNames(ontology).filter((name) => name
|
|
142
|
+
const declared = userRoleNames(ontology).filter((name) => !implicitRoleNames(ontology.roles).includes(name));
|
|
142
143
|
return declared.length > 0
|
|
143
144
|
? Schema.Literals(declared)
|
|
144
145
|
: Schema.String.check(Schema.makeFilter(() => "Expected a role of the ontology, which declares none"));
|
|
145
146
|
}
|
|
146
|
-
/**
|
|
147
|
-
|
|
147
|
+
/**
|
|
148
|
+
* A role to revoke: any assigned role, including one the ontology no longer declares, but not the
|
|
149
|
+
* implicit `member` while the ontology declares one.
|
|
150
|
+
*/
|
|
151
|
+
function revocableRole(ontology) {
|
|
152
|
+
// @legacy ontology.implicit-member
|
|
153
|
+
const implicit = implicitMemberOf(ontology.roles) !== undefined;
|
|
154
|
+
return Schema.String.check(Schema.makeFilter((role) => !implicit ||
|
|
155
|
+
role !== MEMBER_ROLE ||
|
|
156
|
+
`${MEMBER_ROLE} is held by every active member and is never revoked`));
|
|
157
|
+
}
|
|
148
158
|
/**
|
|
149
159
|
* The built-in user's actions: inviting a member and changing a member's roles and activation, each
|
|
150
160
|
* through the runtime's member writes, which the `User` handle and the console share. Each returns
|
|
@@ -186,7 +196,7 @@ function memberActions(ontology, entity) {
|
|
|
186
196
|
"ignored. Give roles or all, not both.",
|
|
187
197
|
input: Schema.Struct({
|
|
188
198
|
id: member("revoke the roles from"),
|
|
189
|
-
roles: Schema.optionalKey(Schema.Array(revocableRole).annotate({ description: "The roles to revoke." })),
|
|
199
|
+
roles: Schema.optionalKey(Schema.Array(revocableRole(ontology)).annotate({ description: "The roles to revoke." })),
|
|
190
200
|
all: Schema.optionalKey(Schema.Literal(true).annotate({ description: "Revoke every role the member holds." })),
|
|
191
201
|
}).check(Schema.makeFilter((input) => (input.roles === undefined) !== (input.all === undefined) ||
|
|
192
202
|
"Expected roles or all: true, not both")),
|