@segmentstream/ontology 0.106.3 → 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 +49 -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.js +8 -1
- 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/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/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
|
@@ -761,10 +761,10 @@ function withMcpPrincipal(request, verifyToken, verifyRuntime, backend, answer,
|
|
|
761
761
|
const origin = publicOrigin(request);
|
|
762
762
|
const runtime = runtimeCredential(verifyRuntime, request);
|
|
763
763
|
// With the OAuth tables, members' access tokens work here, and a 401 tells the client where
|
|
764
|
-
// the member authorizes it. The app's agent calls as the member it names, or, running
|
|
765
|
-
// workflow handed it, as the workflow's user.
|
|
764
|
+
// the member authorizes it. The app's agent calls as the member or guest it names, or, running
|
|
765
|
+
// a task a workflow handed it, as the workflow's user.
|
|
766
766
|
return yield* withPrincipal(bearer, verifyToken, backend, answer, {
|
|
767
|
-
...(runtime === undefined ? {} : { runtime }),
|
|
767
|
+
...(runtime === undefined ? {} : { runtime, guests: true }),
|
|
768
768
|
...(workspaceId === undefined ? {} : { agentTasks: { workspaceId } }),
|
|
769
769
|
...(backend.oauth === undefined
|
|
770
770
|
? {}
|
|
@@ -99,6 +99,8 @@ export declare function mcpTools(built: BuiltApi, chatHistory?: boolean, storage
|
|
|
99
99
|
}, navigation?: boolean): ReadonlyArray<McpTool>;
|
|
100
100
|
/**
|
|
101
101
|
* The tools a caller may see: those whose every permission the caller's roles grant, each with the
|
|
102
|
-
* caller's input schema.
|
|
102
|
+
* caller's input schema. A guest sees none of the tools only a user has.
|
|
103
103
|
*/
|
|
104
|
-
export declare function visibleTools(tools: ReadonlyArray<McpTool>, caller: PermissionHolder
|
|
104
|
+
export declare function visibleTools(tools: ReadonlyArray<McpTool>, caller: PermissionHolder & {
|
|
105
|
+
readonly kind?: string;
|
|
106
|
+
}, provenance?: CallerContext): ReadonlyArray<McpTool>;
|
|
@@ -940,13 +940,25 @@ export function mcpTools(built, chatHistory = false, storage = {}, navigation =
|
|
|
940
940
|
: {}),
|
|
941
941
|
}));
|
|
942
942
|
}
|
|
943
|
+
/**
|
|
944
|
+
* The tools only a user has: who they are, their files and attachments, and the chats they take
|
|
945
|
+
* part in. A guest is no user, so none of them is listed or run for a guest.
|
|
946
|
+
*/
|
|
947
|
+
const USER_TOOL_TARGETS = new Set([
|
|
948
|
+
"me",
|
|
949
|
+
"member-file",
|
|
950
|
+
"chat-search",
|
|
951
|
+
"chat-list",
|
|
952
|
+
"chat-history",
|
|
953
|
+
]);
|
|
943
954
|
/**
|
|
944
955
|
* The tools a caller may see: those whose every permission the caller's roles grant, each with the
|
|
945
|
-
* caller's input schema.
|
|
956
|
+
* caller's input schema. A guest sees none of the tools only a user has.
|
|
946
957
|
*/
|
|
947
958
|
export function visibleTools(tools, caller, provenance = { kind: "unverified" }) {
|
|
948
959
|
return tools.flatMap((tool) => {
|
|
949
|
-
if (
|
|
960
|
+
if ((caller.kind === "guest" && USER_TOOL_TARGETS.has(tool.target.kind)) ||
|
|
961
|
+
!runtimeAllows(provenance, tool) ||
|
|
950
962
|
(tool.target.kind === "toolset" && isReadScoped(provenance)) ||
|
|
951
963
|
!tool.permissions.every((required) => isAllowed(required, caller))) {
|
|
952
964
|
return [];
|
|
@@ -120,9 +120,15 @@ export function callerOfAccessToken(store, token, resource) {
|
|
|
120
120
|
if (!sameResource(grant.resource, resource)) {
|
|
121
121
|
return yield* rejectedAccessToken("resource_mismatch", grant.id);
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
// A grant without a user is a guest's, to the agent alone, and only while guests are admitted.
|
|
124
|
+
const member = grant.userId === null
|
|
125
|
+
? yield* store.guestPrincipal?.(grant) ?? Effect.succeed(undefined)
|
|
126
|
+
: yield* store.memberPrincipal(grant.userId);
|
|
124
127
|
const client = yield* store.findClient(grant.clientId);
|
|
125
|
-
if (member === undefined ||
|
|
128
|
+
if (member === undefined ||
|
|
129
|
+
(grant.userId === null
|
|
130
|
+
? member.kind !== "guest" || member.id !== grant.id
|
|
131
|
+
: member.kind !== "member" || member.id !== grant.userId)) {
|
|
126
132
|
return yield* rejectedAccessToken("member_unavailable", grant.id);
|
|
127
133
|
}
|
|
128
134
|
if (client === undefined || client.id !== grant.clientId) {
|
|
@@ -579,7 +579,11 @@ function token(store, graceMs) {
|
|
|
579
579
|
if (params.resource !== undefined && !sameResource(params.resource, owner.resource)) {
|
|
580
580
|
return oauthError("invalid_target", "The grant is for a different resource.");
|
|
581
581
|
}
|
|
582
|
-
|
|
582
|
+
// A guest's grant names no user; it renews while the ontology admits guests.
|
|
583
|
+
const holder = owner.userId === null
|
|
584
|
+
? yield* store.guestPrincipal?.(owner) ?? Effect.succeed(undefined)
|
|
585
|
+
: yield* store.memberPrincipal(owner.userId);
|
|
586
|
+
if (holder === undefined) {
|
|
583
587
|
// Deny access without permanently destroying authorization on an inconclusive lookup.
|
|
584
588
|
return oauthError("invalid_grant", "The member can no longer use this app.");
|
|
585
589
|
}
|
|
@@ -127,7 +127,11 @@ export type DevicePoll = {
|
|
|
127
127
|
export interface OAuthGrant {
|
|
128
128
|
readonly id: string;
|
|
129
129
|
readonly clientId: string;
|
|
130
|
-
|
|
130
|
+
/**
|
|
131
|
+
* The user the grant acts for; `null` for a guest's grant to the agent (`agent-web`), whose id is
|
|
132
|
+
* the guest's, since a guest is no user.
|
|
133
|
+
*/
|
|
134
|
+
readonly userId: string | null;
|
|
131
135
|
readonly scope: string;
|
|
132
136
|
readonly resource: string;
|
|
133
137
|
/** Present on access-token lookup, for absolute session expiry. */
|
|
@@ -191,8 +195,10 @@ export interface OAuthStore {
|
|
|
191
195
|
readonly findRequest: (id: string) => Effect.Effect<OAuthRequest | undefined>;
|
|
192
196
|
/** Removes a request that has not expired and returns it: a request is decided once. */
|
|
193
197
|
readonly takeRequest: (id: string) => Effect.Effect<OAuthRequest | undefined>;
|
|
194
|
-
/** Records a grant, with its PKCE code when using browser authorization. */
|
|
195
|
-
readonly saveGrant: (grant: OAuthGrant
|
|
198
|
+
/** Records a member's grant, with its PKCE code when using browser authorization. */
|
|
199
|
+
readonly saveGrant: (grant: OAuthGrant & {
|
|
200
|
+
readonly userId: string;
|
|
201
|
+
}, code?: OAuthToken) => Effect.Effect<void>;
|
|
196
202
|
/** Uses a code or refresh token, once, before it expires and while its grant stands. */
|
|
197
203
|
readonly useToken: (hash: string, kind: "code" | "refresh") => Effect.Effect<UsedOAuthToken>;
|
|
198
204
|
/** Stores new tokens, and forgets the expired ones. */
|
|
@@ -204,6 +210,11 @@ export interface OAuthStore {
|
|
|
204
210
|
readonly revokeGrant: (id: string) => Effect.Effect<void>;
|
|
205
211
|
/** The member a grant acts for, with the roles they hold now; undefined once they may not sign in. */
|
|
206
212
|
readonly memberPrincipal: (userId: string) => Effect.Effect<Principal | undefined>;
|
|
213
|
+
/**
|
|
214
|
+
* The guest a grant without a user stands for: a guest's grant to the agent (`agent-web`) while
|
|
215
|
+
* the ontology admits guests; `undefined` for any other grant. Absent on a store without guests.
|
|
216
|
+
*/
|
|
217
|
+
readonly guestPrincipal?: (grant: OAuthGrant) => Effect.Effect<Principal | undefined>;
|
|
207
218
|
}
|
|
208
219
|
/** A channel account waiting, for ten minutes, for a member to claim it with its pairing code. */
|
|
209
220
|
export interface AgentPairing {
|
|
@@ -258,9 +269,30 @@ export interface AgentWebStore {
|
|
|
258
269
|
* Counts one turn a member starts on the web against the agent's limits when `signUp` created
|
|
259
270
|
* them, as their turns on a messenger are counted, on the same counters; invited and paired
|
|
260
271
|
* members are never counted. Their `onSignUp`, if it is still pending, runs again first. The
|
|
261
|
-
* limit the turn exceeds, or `undefined` when it may run.
|
|
272
|
+
* limit the turn exceeds, or `undefined` when it may run. `limits`, the agent's own, are kept as
|
|
273
|
+
* a messenger's turn keeps them, before counting.
|
|
274
|
+
*/
|
|
275
|
+
readonly countTurn: (userId: string, limits?: ResolveIdentityInput["limits"]) => Effect.Effect<WebTurnLimit | undefined>;
|
|
276
|
+
/**
|
|
277
|
+
* The guest an `agent-web` grant without a user stands for, while it stands and the ontology
|
|
278
|
+
* admits guests; `undefined` otherwise. The grant's id is the guest's.
|
|
279
|
+
*/
|
|
280
|
+
readonly grantGuest?: (grantId: string) => Effect.Effect<Principal | undefined>;
|
|
281
|
+
/**
|
|
282
|
+
* Counts one turn a guest starts against the agent's guest limits, per guest and for every guest
|
|
283
|
+
* together, apart from the counters of people who signed up. `limits` are kept first, as for
|
|
284
|
+
* {@link countTurn}. The limit the turn exceeds, or `undefined` when it may run.
|
|
285
|
+
*/
|
|
286
|
+
readonly countGuestTurn?: (guestId: string, limits?: ResolveIdentityInput["limits"]) => Effect.Effect<WebTurnLimit | undefined>;
|
|
287
|
+
/**
|
|
288
|
+
* A new guest of a declared website: a grant to the agent at `resource` that names no user, with
|
|
289
|
+
* its access and refresh tokens. No user or identity is created. `client` keys how many guests one
|
|
290
|
+
* network address may start an hour; it counts toward no limit of new users.
|
|
262
291
|
*/
|
|
263
|
-
readonly
|
|
292
|
+
readonly guest?: (input: {
|
|
293
|
+
readonly resource: string;
|
|
294
|
+
readonly client: string;
|
|
295
|
+
}) => Effect.Effect<GuestIssue>;
|
|
264
296
|
/**
|
|
265
297
|
* Signs up a new visitor of a website on `web`: the user `signUp` creates for them, and the access
|
|
266
298
|
* and refresh tokens of their grant to the agent at `resource`. `client` keys how many visitors one
|
|
@@ -285,6 +317,20 @@ export type VisitorSignUp = {
|
|
|
285
317
|
} | {
|
|
286
318
|
readonly status: "refused";
|
|
287
319
|
};
|
|
320
|
+
/** A guest's credential, as {@link AgentWebStore.guest} answers it. */
|
|
321
|
+
export type GuestIssue = {
|
|
322
|
+
readonly status: "issued";
|
|
323
|
+
/** The guest's id: the id of their grant, which names no user. */
|
|
324
|
+
readonly guestId: string;
|
|
325
|
+
readonly token: string;
|
|
326
|
+
readonly refreshToken: string;
|
|
327
|
+
readonly expiresAt: Date;
|
|
328
|
+
} | {
|
|
329
|
+
readonly status: "limited";
|
|
330
|
+
readonly retryAfterSeconds: number;
|
|
331
|
+
} | {
|
|
332
|
+
readonly status: "refused";
|
|
333
|
+
};
|
|
288
334
|
/** The limit a member's turn on the web exceeds, and when the next one may run. */
|
|
289
335
|
export interface WebTurnLimit {
|
|
290
336
|
readonly scope: AgentLimitScope;
|
|
@@ -303,8 +349,13 @@ export interface AgentLimits {
|
|
|
303
349
|
};
|
|
304
350
|
readonly newUsersPerHour: number;
|
|
305
351
|
readonly workspaceTurnsPerDay: number;
|
|
352
|
+
/** Guests' turns, apart from those of people who signed up: per guest and for all together. */
|
|
353
|
+
readonly guest: {
|
|
354
|
+
readonly turnsPerDay: number;
|
|
355
|
+
readonly workspaceTurnsPerDay: number;
|
|
356
|
+
};
|
|
306
357
|
}
|
|
307
|
-
export type AgentLimitScope = "turnsPerMinute" | "turnsPerDay" | "newUsersPerHour" | "workspaceTurnsPerDay";
|
|
358
|
+
export type AgentLimitScope = "turnsPerMinute" | "turnsPerDay" | "newUsersPerHour" | "workspaceTurnsPerDay" | "guestTurnsPerDay" | "guestWorkspaceTurnsPerDay" | "newGuestsPerHour";
|
|
308
359
|
export interface ResolveIdentityInput {
|
|
309
360
|
readonly provider: string;
|
|
310
361
|
readonly externalId: string;
|
|
@@ -323,6 +374,7 @@ export interface ResolveIdentityInput {
|
|
|
323
374
|
readonly perSender?: Partial<AgentLimits["perSender"]>;
|
|
324
375
|
readonly newUsersPerHour?: number;
|
|
325
376
|
readonly workspaceTurnsPerDay?: number;
|
|
377
|
+
readonly guest?: Partial<AgentLimits["guest"]>;
|
|
326
378
|
};
|
|
327
379
|
}
|
|
328
380
|
/** Verified provider facts only; channel-app callers cannot submit policy or bot-turn fields. */
|
|
@@ -428,6 +428,10 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
428
428
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
429
429
|
}>>;
|
|
430
430
|
readonly onSignUp: Schema.optionalKey<Schema.String>;
|
|
431
|
+
readonly guest: Schema.optionalKey<Schema.Struct<{
|
|
432
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
433
|
+
readonly origins: Schema.$Array<Schema.String>;
|
|
434
|
+
}>>;
|
|
431
435
|
}>, {
|
|
432
436
|
readonly onNewUser: "on_new_user";
|
|
433
437
|
readonly codeLink: "code_link";
|
|
@@ -704,6 +708,10 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
704
708
|
readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
|
|
705
709
|
}>>;
|
|
706
710
|
readonly onSignUp: Schema.optionalKey<Schema.String>;
|
|
711
|
+
readonly guest: Schema.optionalKey<Schema.Struct<{
|
|
712
|
+
readonly channels: Schema.$Array<Schema.String>;
|
|
713
|
+
readonly origins: Schema.$Array<Schema.String>;
|
|
714
|
+
}>>;
|
|
707
715
|
}>, {
|
|
708
716
|
readonly onNewUser: "on_new_user";
|
|
709
717
|
readonly codeLink: "code_link";
|
package/dist/service/service.js
CHANGED
|
@@ -9,8 +9,9 @@ import { RuntimeDeployment } from "../runtime/deployment.js";
|
|
|
9
9
|
import { nameToWire } from "../authoring-names.js";
|
|
10
10
|
import { bundledNavigationCatalog } from "../navigation-artifact.js";
|
|
11
11
|
import { parsePageCatalog } from "../navigation-catalog.js";
|
|
12
|
-
import { signUpOriginsOf } from "../manifest.js";
|
|
12
|
+
import { guestOf, signUpOriginsOf } from "../manifest.js";
|
|
13
13
|
import { isAllowed } from "../permissions.js";
|
|
14
|
+
import { agentToolsFor } from "../runtime/guests.js";
|
|
14
15
|
import { sqlServiceRuntime } from "../runtime/service-binding.js";
|
|
15
16
|
import { neonSignInLinks, segmentstreamSignInLinks } from "../runtime/sign-in-links.js";
|
|
16
17
|
import { memberFileRoutes } from "./member-file-routes.js";
|
|
@@ -350,13 +351,19 @@ export function createOntologyService(ontology, config) {
|
|
|
350
351
|
ErrorResponsesLive,
|
|
351
352
|
storageMaintenanceAuthenticationLayer(config.storageMaintenanceKey),
|
|
352
353
|
]));
|
|
353
|
-
|
|
354
|
+
// The websites whose visitors are guests, and those whose visitors still sign up on web.
|
|
355
|
+
// @legacy ontology.sign-up-web
|
|
356
|
+
const visitorWebsites = {
|
|
357
|
+
guests: guestOf(ontology.manifest)?.origins ?? [],
|
|
358
|
+
signUp: signUpOriginsOf(ontology.manifest),
|
|
359
|
+
};
|
|
360
|
+
const visitors = visitorWebsites.guests.length > 0 || visitorWebsites.signUp.length > 0;
|
|
354
361
|
const oauth = preview
|
|
355
362
|
? Layer.empty
|
|
356
363
|
: oauthLayer({ verifyToken, refreshReuseGraceMs: config.oauthRefreshReuseGraceMs });
|
|
357
364
|
const mcp = config.mcp === false
|
|
358
365
|
? // A website's visitors renew their agent tokens at the OAuth token endpoint.
|
|
359
|
-
|
|
366
|
+
visitors
|
|
360
367
|
? oauth
|
|
361
368
|
: Layer.empty
|
|
362
369
|
: Layer.mergeAll(mcpLayer({
|
|
@@ -375,13 +382,16 @@ export function createOntologyService(ontology, config) {
|
|
|
375
382
|
workspaceId: config.workspaceId,
|
|
376
383
|
decide: config.decisions,
|
|
377
384
|
}), oauth);
|
|
385
|
+
// Every answer that tells the agent whom it acts for names the agent's own tools they hold.
|
|
386
|
+
const agentTools = (principal) => agentToolsFor(ontology, principal);
|
|
378
387
|
const agent = preview
|
|
379
388
|
? Layer.empty
|
|
380
389
|
: agentLayer({
|
|
381
390
|
verifyToken,
|
|
382
391
|
verifyRuntime,
|
|
383
392
|
exchangeSession,
|
|
384
|
-
|
|
393
|
+
visitorWebsites,
|
|
394
|
+
agentTools,
|
|
385
395
|
});
|
|
386
396
|
const agentTasks = preview
|
|
387
397
|
? Layer.empty
|
|
@@ -390,6 +400,7 @@ export function createOntologyService(ontology, config) {
|
|
|
390
400
|
verifyRuntime,
|
|
391
401
|
workspaceId: config.workspaceId,
|
|
392
402
|
engine: config.workflowEngine ?? vercelWorkflowEngine,
|
|
403
|
+
agentTools,
|
|
393
404
|
});
|
|
394
405
|
const attachments = preview
|
|
395
406
|
? Layer.empty
|
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",
|