@segmentstream/ontology 0.106.2 → 0.107.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 +55 -0
- package/README.md +38 -8
- package/dist/analyze.d.ts +7 -1
- package/dist/analyze.js +237 -13
- package/dist/authoring.js +6 -0
- package/dist/diagnostics.d.ts +3 -3
- package/dist/diagnostics.js +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +5 -3
- package/dist/manifest.d.ts +69 -1
- package/dist/manifest.js +51 -4
- package/dist/migrate/apply.d.ts +6 -0
- package/dist/migrate/apply.js +25 -5
- package/dist/migrate/model.d.ts +32 -0
- package/dist/migrate/storage.d.ts +2 -0
- package/dist/migrate/storage.js +8 -0
- package/dist/names.d.ts +5 -0
- package/dist/names.js +5 -0
- package/dist/ontology.d.ts +4 -1
- package/dist/permissions.d.ts +30 -2
- package/dist/permissions.js +51 -6
- package/dist/replication/shadow.d.ts +4 -2
- package/dist/replication/shadow.js +1 -1
- package/dist/replication/store.js +4 -0
- package/dist/runtime/agent-counters.d.ts +5 -1
- package/dist/runtime/agent-counters.js +21 -6
- package/dist/runtime/agent-web.d.ts +9 -6
- package/dist/runtime/agent-web.js +101 -5
- package/dist/runtime/generated-actions.js +2 -3
- package/dist/runtime/guests.d.ts +32 -0
- package/dist/runtime/guests.js +64 -0
- package/dist/runtime/new-user-hook.js +2 -1
- package/dist/runtime/oauth.js +7 -1
- package/dist/runtime/pipeline.js +3 -2
- package/dist/runtime/principals.js +6 -4
- package/dist/runtime/service-binding.js +2 -2
- package/dist/runtime/sql-runtime.js +2 -1
- package/dist/runtime.d.ts +10 -2
- package/dist/service/agent/authentication.d.ts +6 -4
- package/dist/service/agent/authentication.js +20 -5
- package/dist/service/agent/protocol.d.ts +28 -2
- package/dist/service/agent/protocol.js +23 -10
- package/dist/service/agent/server.d.ts +9 -2
- package/dist/service/agent/server.js +12 -12
- package/dist/service/agent/tasks.d.ts +3 -0
- package/dist/service/agent/tasks.js +5 -3
- package/dist/service/agent/web-tokens.d.ts +28 -13
- package/dist/service/agent/web-tokens.js +91 -38
- package/dist/service/authentication.d.ts +6 -0
- package/dist/service/authentication.js +11 -2
- package/dist/service/chat/review-delivery.js +4 -0
- package/dist/service/mcp/server.js +3 -3
- package/dist/service/mcp/tools.d.ts +4 -2
- package/dist/service/mcp/tools.js +14 -2
- package/dist/service/oauth/protocol.js +8 -2
- package/dist/service/oauth/server.js +5 -1
- package/dist/service/runtime-contract.d.ts +58 -6
- package/dist/service/schemas.d.ts +8 -0
- package/dist/service/service.js +15 -4
- package/dist/sign-in.d.ts +58 -9
- package/dist/sign-in.js +87 -9
- package/package.json +1 -1
package/dist/sign-in.d.ts
CHANGED
|
@@ -12,8 +12,9 @@ export declare const CHANNEL_PROVIDERS: readonly ["telegram"];
|
|
|
12
12
|
export type ChannelProvider = (typeof CHANNEL_PROVIDERS)[number];
|
|
13
13
|
/**
|
|
14
14
|
* The channels a stranger may sign up through. `email` is sign-in by email code in the app; `web`
|
|
15
|
-
* is a visitor who writes to the agent from one of the websites `signUp.origins` names
|
|
16
|
-
* are a first private message to the agent, or opening the
|
|
15
|
+
* is a visitor who writes to the agent from one of the websites `signUp.origins` names, which
|
|
16
|
+
* `guest` supersedes; the others are a first private message to the agent, or opening the
|
|
17
|
+
* Telegram Mini App.
|
|
17
18
|
*/
|
|
18
19
|
export declare const SIGN_UP_CHANNELS: readonly ["email", "telegram", "whatsapp", "web"];
|
|
19
20
|
export type SignUpChannel = (typeof SIGN_UP_CHANNELS)[number];
|
|
@@ -32,9 +33,9 @@ export interface SignUpOptions<R = unknown> {
|
|
|
32
33
|
/** Roles for a listed channel that differs from `roles`. */
|
|
33
34
|
readonly byChannel?: Readonly<Partial<Record<SignUpChannel, ReadonlyArray<R>>>>;
|
|
34
35
|
/**
|
|
35
|
-
* The websites whose visitors may sign up on `web`,
|
|
36
|
-
* `https://www.example.com`: the agent's sign-up answers a browser
|
|
37
|
-
*
|
|
36
|
+
* The websites whose visitors may sign up on `web`, as {@link websiteOrigin} accepts them, such
|
|
37
|
+
* as `https://www.example.com` or `https://*.example.com`: the agent's sign-up answers a browser
|
|
38
|
+
* on one of them. Required with `web`.
|
|
38
39
|
*/
|
|
39
40
|
readonly origins?: ReadonlyArray<string>;
|
|
40
41
|
}
|
|
@@ -44,12 +45,58 @@ export interface ResolvedSignUp {
|
|
|
44
45
|
/** The websites whose visitors may sign up on `web`, by origin. */
|
|
45
46
|
readonly origins?: ReadonlyArray<string>;
|
|
46
47
|
}
|
|
48
|
+
/** The channels a guest talks to the agent through: only `web`, a website's chat, so far. */
|
|
49
|
+
export declare const GUEST_CHANNELS: readonly ["web"];
|
|
50
|
+
export type GuestChannel = (typeof GUEST_CHANNELS)[number];
|
|
51
|
+
export declare function isGuestChannel(value: unknown): value is GuestChannel;
|
|
47
52
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
53
|
+
* Who may talk to the agent without signing in or signing up: a guest, the counterpart of the
|
|
54
|
+
* built-in `member`. A guest is a session, not a user: nobody proved who they are, so no user or
|
|
55
|
+
* identity record is created for them, and they hold the built-in role `guest` alone. Without
|
|
56
|
+
* `guest`, nobody chats without signing in or signing up.
|
|
51
57
|
*/
|
|
52
|
-
export
|
|
58
|
+
export interface GuestOptions<P = unknown> {
|
|
59
|
+
/** Where guests talk to the agent: `["web"]`, a declared website's chat. */
|
|
60
|
+
readonly channels: ReadonlyArray<GuestChannel>;
|
|
61
|
+
/**
|
|
62
|
+
* The websites whose visitors are guests, as {@link websiteOrigin} accepts them, such as
|
|
63
|
+
* `https://www.example.com` or `https://*.example.com`.
|
|
64
|
+
*/
|
|
65
|
+
readonly origins: ReadonlyArray<string>;
|
|
66
|
+
/**
|
|
67
|
+
* What every guest may do, as role permissions: the permissions of the built-in role `guest`.
|
|
68
|
+
* `check` holds them to the rules of sign-up roles, and a guest has no user record, so a scope
|
|
69
|
+
* cannot use `me`. `[]` lets guests talk to the agent and nothing more.
|
|
70
|
+
*/
|
|
71
|
+
readonly permissions: ReadonlyArray<P>;
|
|
72
|
+
}
|
|
73
|
+
/** Guests as the manifest carries them; the built-in role `guest` holds their permissions. */
|
|
74
|
+
export interface ResolvedGuest {
|
|
75
|
+
readonly channels: ReadonlyArray<GuestChannel>;
|
|
76
|
+
readonly origins: ReadonlyArray<string>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* A website's origin as `guest.origins` and `signUp.origins` accept it, written as an origin alone,
|
|
80
|
+
* without a path, and lowercase:
|
|
81
|
+
*
|
|
82
|
+
* - the exact origin of an `https` address, such as `https://www.example.com`;
|
|
83
|
+
* - the exact origin of an `http` address on `localhost` or `127.0.0.1`, for development;
|
|
84
|
+
* - a pattern whose leftmost label is `*`, under a domain of at least two labels that is not a
|
|
85
|
+
* shared second-level domain such as `co.uk`: `https://*.example.com` or
|
|
86
|
+
* `https://*.vercel.app`. `*` stands for exactly one whole label: the pattern matches
|
|
87
|
+
* `https://www.example.com` and `https://pr-12.example.com`, not `https://example.com` or
|
|
88
|
+
* `https://a.b.example.com`. A pattern under a domain others share, such as `vercel.app`,
|
|
89
|
+
* admits their websites too.
|
|
90
|
+
*/
|
|
91
|
+
export declare function websiteOrigin(value: unknown): string | undefined;
|
|
92
|
+
/** @deprecated Use {@link websiteOrigin}, which `signUp.origins` and `guest.origins` share. */
|
|
93
|
+
export declare const signUpOrigin: typeof websiteOrigin;
|
|
94
|
+
/**
|
|
95
|
+
* Whether a browser's `Origin` is one of the declared websites, each an origin
|
|
96
|
+
* {@link websiteOrigin} accepted: equal to an exact one, or an `https` origin on the default port
|
|
97
|
+
* whose host is one label and a pattern's domain.
|
|
98
|
+
*/
|
|
99
|
+
export declare function matchesWebsite(declared: ReadonlyArray<string>, origin: unknown): boolean;
|
|
53
100
|
/** How people become members of the app. Email and channel admission are independent. */
|
|
54
101
|
export interface SignInOptions {
|
|
55
102
|
readonly policy: SignInPolicy;
|
|
@@ -68,6 +115,8 @@ export interface SignInOptions {
|
|
|
68
115
|
/** The sign-in options of a checked ontology, with the sign-up its definition declares. */
|
|
69
116
|
export interface ResolvedSignInOptions extends SignInOptions {
|
|
70
117
|
readonly signUp?: ResolvedSignUp;
|
|
118
|
+
/** Where guests talk to the agent, when the definition declares `guest`. */
|
|
119
|
+
readonly guest?: ResolvedGuest;
|
|
71
120
|
/** Wire name of the idempotent, input-free action run as each user created by sign-up. */
|
|
72
121
|
readonly onSignUp?: string;
|
|
73
122
|
}
|
package/dist/sign-in.js
CHANGED
|
@@ -11,8 +11,9 @@ export const DEFAULT_SIGN_IN_POLICY = "invited";
|
|
|
11
11
|
export const CHANNEL_PROVIDERS = ["telegram"];
|
|
12
12
|
/**
|
|
13
13
|
* The channels a stranger may sign up through. `email` is sign-in by email code in the app; `web`
|
|
14
|
-
* is a visitor who writes to the agent from one of the websites `signUp.origins` names
|
|
15
|
-
* are a first private message to the agent, or opening the
|
|
14
|
+
* is a visitor who writes to the agent from one of the websites `signUp.origins` names, which
|
|
15
|
+
* `guest` supersedes; the others are a first private message to the agent, or opening the
|
|
16
|
+
* Telegram Mini App.
|
|
16
17
|
*/
|
|
17
18
|
export const SIGN_UP_CHANNELS = ["email", "telegram", "whatsapp", "web"];
|
|
18
19
|
/** The sign-up channels a person reaches through a chat, which need a matching `chat` adapter. */
|
|
@@ -20,25 +21,102 @@ export const SIGN_UP_CHAT_CHANNELS = ["telegram", "whatsapp"];
|
|
|
20
21
|
export function isSignUpChannel(value) {
|
|
21
22
|
return SIGN_UP_CHANNELS.includes(value);
|
|
22
23
|
}
|
|
24
|
+
/** The channels a guest talks to the agent through: only `web`, a website's chat, so far. */
|
|
25
|
+
export const GUEST_CHANNELS = ["web"];
|
|
26
|
+
export function isGuestChannel(value) {
|
|
27
|
+
return GUEST_CHANNELS.includes(value);
|
|
28
|
+
}
|
|
29
|
+
/** A DNS label, lowercase, as a browser serializes it in an origin. */
|
|
30
|
+
const DNS_LABEL = /^(?!-)[a-z0-9-]{1,63}(?<!-)$/;
|
|
31
|
+
/** A top-level domain: letters, or an internationalized name in its ASCII form. */
|
|
32
|
+
const TOP_LEVEL_LABEL = /^(?:[a-z]{2,63}|xn--[a-z0-9-]{1,59})$/;
|
|
33
|
+
/**
|
|
34
|
+
* Second-level labels that registries share under a country's domain, such as `co.uk`: a pattern
|
|
35
|
+
* directly under one would admit every company's website there.
|
|
36
|
+
*/
|
|
37
|
+
const SHARED_SECOND_LEVEL = new Set([
|
|
38
|
+
"ac",
|
|
39
|
+
"co",
|
|
40
|
+
"com",
|
|
41
|
+
"edu",
|
|
42
|
+
"go",
|
|
43
|
+
"gov",
|
|
44
|
+
"ne",
|
|
45
|
+
"net",
|
|
46
|
+
"or",
|
|
47
|
+
"org",
|
|
48
|
+
]);
|
|
49
|
+
/** The domain under the `*` of an origin pattern, when the pattern is one websites may declare. */
|
|
50
|
+
function patternSuffix(value) {
|
|
51
|
+
const match = /^https:\/\/\*\.([a-z0-9.-]+)$/.exec(value);
|
|
52
|
+
const labels = match?.[1]?.split(".");
|
|
53
|
+
if (labels === undefined ||
|
|
54
|
+
labels.length < 2 ||
|
|
55
|
+
!labels.every((label) => DNS_LABEL.test(label)) ||
|
|
56
|
+
!TOP_LEVEL_LABEL.test(labels.at(-1)) ||
|
|
57
|
+
(labels.length === 2 && labels[1].length === 2 && SHARED_SECOND_LEVEL.has(labels[0]))) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
return labels.join(".");
|
|
61
|
+
}
|
|
23
62
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
63
|
+
* A website's origin as `guest.origins` and `signUp.origins` accept it, written as an origin alone,
|
|
64
|
+
* without a path, and lowercase:
|
|
65
|
+
*
|
|
66
|
+
* - the exact origin of an `https` address, such as `https://www.example.com`;
|
|
67
|
+
* - the exact origin of an `http` address on `localhost` or `127.0.0.1`, for development;
|
|
68
|
+
* - a pattern whose leftmost label is `*`, under a domain of at least two labels that is not a
|
|
69
|
+
* shared second-level domain such as `co.uk`: `https://*.example.com` or
|
|
70
|
+
* `https://*.vercel.app`. `*` stands for exactly one whole label: the pattern matches
|
|
71
|
+
* `https://www.example.com` and `https://pr-12.example.com`, not `https://example.com` or
|
|
72
|
+
* `https://a.b.example.com`. A pattern under a domain others share, such as `vercel.app`,
|
|
73
|
+
* admits their websites too.
|
|
27
74
|
*/
|
|
28
|
-
export function
|
|
29
|
-
if (typeof value !== "string"
|
|
75
|
+
export function websiteOrigin(value) {
|
|
76
|
+
if (typeof value !== "string") {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (value.startsWith("https://*.")) {
|
|
80
|
+
return patternSuffix(value) === undefined ? undefined : value;
|
|
81
|
+
}
|
|
82
|
+
if (!URL.canParse(value)) {
|
|
30
83
|
return undefined;
|
|
31
84
|
}
|
|
32
85
|
const url = new URL(value);
|
|
33
86
|
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1";
|
|
34
|
-
// The service compares a browser's origin exactly, so a pattern such as `*.example.com` would
|
|
35
|
-
// match nothing.
|
|
36
87
|
return (url.protocol === "https:" || (url.protocol === "http:" && local)) &&
|
|
37
88
|
!url.hostname.includes("*") &&
|
|
38
89
|
url.origin === value
|
|
39
90
|
? url.origin
|
|
40
91
|
: undefined;
|
|
41
92
|
}
|
|
93
|
+
// @legacy ontology.sign-up-origin-name
|
|
94
|
+
/** @deprecated Use {@link websiteOrigin}, which `signUp.origins` and `guest.origins` share. */
|
|
95
|
+
export const signUpOrigin = websiteOrigin;
|
|
96
|
+
/**
|
|
97
|
+
* Whether a browser's `Origin` is one of the declared websites, each an origin
|
|
98
|
+
* {@link websiteOrigin} accepted: equal to an exact one, or an `https` origin on the default port
|
|
99
|
+
* whose host is one label and a pattern's domain.
|
|
100
|
+
*/
|
|
101
|
+
export function matchesWebsite(declared, origin) {
|
|
102
|
+
if (typeof origin !== "string" || origin === "") {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
return declared.some((candidate) => {
|
|
106
|
+
if (candidate === origin) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
const suffix = candidate.startsWith("https://*.") ? patternSuffix(candidate) : undefined;
|
|
110
|
+
if (suffix === undefined || !origin.startsWith("https://")) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
const host = origin.slice("https://".length);
|
|
114
|
+
const label = host.endsWith(`.${suffix}`)
|
|
115
|
+
? host.slice(0, host.length - suffix.length - 1)
|
|
116
|
+
: undefined;
|
|
117
|
+
return label !== undefined && DNS_LABEL.test(label);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
42
120
|
/**
|
|
43
121
|
* How a person signs in with an address. `code`: a six-digit code, for a member who has signed in
|
|
44
122
|
* with Neon Auth before, so their Neon Auth account exists. `link`: an emailed sign-in link, for
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.107.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",
|