@segmentstream/ontology 0.94.1 → 0.96.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/README.md +52 -7
- package/dist/analyze.d.ts +15 -3
- package/dist/analyze.js +217 -5
- package/dist/authoring.js +3 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +5 -5
- package/dist/manifest-compatibility.d.ts +7 -0
- package/dist/manifest-compatibility.js +12 -0
- package/dist/manifest.d.ts +102 -18
- package/dist/manifest.js +41 -2
- package/dist/migrate/apply.d.ts +3 -2
- package/dist/migrate/apply.js +11 -3
- package/dist/migrate/model.d.ts +60 -12
- package/dist/migrate/plan.js +9 -1
- package/dist/migrate/storage.d.ts +7 -0
- package/dist/migrate/storage.js +24 -12
- package/dist/ontology.d.ts +2 -2
- package/dist/permissions.d.ts +9 -0
- package/dist/permissions.js +8 -0
- package/dist/runtime/channel-identity-admin.d.ts +41 -0
- package/dist/runtime/channel-identity-admin.js +223 -0
- package/dist/runtime/generated-actions.d.ts +2 -1
- package/dist/runtime/generated-actions.js +71 -3
- package/dist/runtime/member-tables.d.ts +7 -2
- package/dist/runtime/member-tables.js +18 -3
- package/dist/runtime/new-user-hook.d.ts +11 -1
- package/dist/runtime/new-user-hook.js +69 -29
- package/dist/runtime/pipeline.d.ts +2 -0
- package/dist/runtime/pipeline.js +11 -3
- package/dist/runtime/principals.d.ts +37 -3
- package/dist/runtime/principals.js +140 -36
- package/dist/runtime/resolve-agent-identity.js +43 -12
- package/dist/runtime/service-binding.js +11 -4
- package/dist/runtime/sql-runtime.d.ts +14 -1
- package/dist/runtime/sql-runtime.js +9 -0
- package/dist/runtime/user-identities.d.ts +5 -3
- package/dist/runtime/user-identities.js +9 -4
- package/dist/runtime/user-identity-sql.d.ts +4 -1
- package/dist/runtime/user-identity-sql.js +5 -2
- package/dist/runtime-source.d.ts +6 -0
- package/dist/runtime-source.js +11 -0
- package/dist/service/agent/attachments.js +4 -0
- package/dist/service/agent/authentication.d.ts +74 -2
- package/dist/service/agent/authentication.js +93 -11
- package/dist/service/agent/files.js +8 -1
- package/dist/service/agent/server.js +13 -2
- package/dist/service/authentication.js +58 -2
- package/dist/service/caller-context.d.ts +16 -0
- package/dist/service/chat/envelope.d.ts +20 -2
- package/dist/service/chat/envelope.js +10 -0
- package/dist/service/runtime-contract.d.ts +9 -0
- package/dist/service/schemas.d.ts +12 -0
- package/dist/sign-in.d.ts +32 -1
- package/dist/sign-in.js +12 -1
- package/dist/storage/attachments.d.ts +11 -0
- package/dist/user-identity.d.ts +14 -5
- package/dist/user-identity.js +25 -5
- package/package.json +1 -1
|
@@ -11,7 +11,8 @@ import { RequestId, crossOriginSession, forbidden, internalError, notInvited, to
|
|
|
11
11
|
import { ACCESS_TOKEN_PREFIX, appSessionResource, publicOrigin, callerOfAccessToken, rejectedAccessToken, } from "./oauth/protocol.js";
|
|
12
12
|
import { CurrentCaller } from "./caller-context.js";
|
|
13
13
|
import { OntologyBackend } from "./runtime-contract.js";
|
|
14
|
-
import { ACT_AS_HEADER, AGENT_TASK_HEADER, logRuntimeRejection, runtimeCredential, } from "./runtime-identity.js";
|
|
14
|
+
import { ACT_AS_HEADER, ACT_AS_PROVIDER_HEADER, AGENT_TASK_HEADER, logRuntimeRejection, runtimeCredential, } from "./runtime-identity.js";
|
|
15
|
+
import { delegatedAccount } from "./agent/authentication.js";
|
|
15
16
|
import { agentTaskCaller } from "./agent/task-caller.js";
|
|
16
17
|
import { ErrorSchemas } from "./schemas.js";
|
|
17
18
|
const CLOCK_TOLERANCE_SECONDS = 5;
|
|
@@ -478,6 +479,53 @@ function actingMember(actAs, provider) {
|
|
|
478
479
|
};
|
|
479
480
|
});
|
|
480
481
|
}
|
|
482
|
+
/**
|
|
483
|
+
* The member an API key with delegation acts for: an external agent runtime the workspace trusts,
|
|
484
|
+
* which names the member in `X-SegmentStream-Act-As` and the provider of the account they wrote
|
|
485
|
+
* from in `X-SegmentStream-Identity-Provider`, on the routes that accept the deployment's own
|
|
486
|
+
* runtime. The member must be active, unblocked and hold a live account of that provider; the
|
|
487
|
+
* request runs with the roles they hold now, and the key's own user grants nothing. A key with
|
|
488
|
+
* delegation never runs a workflow's task and never acts without naming a member.
|
|
489
|
+
*/
|
|
490
|
+
function delegatedMember(client, runtime) {
|
|
491
|
+
return Effect.gen(function* () {
|
|
492
|
+
const backend = yield* OntologyBackend;
|
|
493
|
+
const refuse = (reason, detail) => Effect.logWarning("ontology.delegation.refused").pipe(Effect.annotateLogs({ client: client.id, reason }), Effect.as({ status: "forbidden", detail }));
|
|
494
|
+
if (runtime === undefined) {
|
|
495
|
+
return yield* refuse("route", "An API key with delegation acts for a member only on the routes the app's agent uses.");
|
|
496
|
+
}
|
|
497
|
+
if (runtime.agentTask !== undefined) {
|
|
498
|
+
return yield* refuse("agent_task", `An API key with delegation acts for a member; it never presents ${AGENT_TASK_HEADER}.`);
|
|
499
|
+
}
|
|
500
|
+
if (runtime.actAs === undefined) {
|
|
501
|
+
return yield* refuse("act_as", `An API key with delegation names the member it acts for in ${ACT_AS_HEADER}.`);
|
|
502
|
+
}
|
|
503
|
+
if (runtime.provider === undefined) {
|
|
504
|
+
return yield* refuse("provider", `An API key with delegation names the provider of the member's account in ` +
|
|
505
|
+
`${ACT_AS_PROVIDER_HEADER}.`);
|
|
506
|
+
}
|
|
507
|
+
const delegated = backend.agents === undefined
|
|
508
|
+
? undefined
|
|
509
|
+
: yield* delegatedAccount(backend.agents, runtime.actAs, runtime.provider);
|
|
510
|
+
if (delegated === undefined) {
|
|
511
|
+
return yield* refuse("member", `The member is inactive or has no live ${runtime.provider} account.`);
|
|
512
|
+
}
|
|
513
|
+
yield* Effect.logInfo("ontology.delegation.authenticated").pipe(Effect.annotateLogs({
|
|
514
|
+
client: client.id,
|
|
515
|
+
member: delegated.member.id,
|
|
516
|
+
provider: runtime.provider,
|
|
517
|
+
}));
|
|
518
|
+
return {
|
|
519
|
+
status: "authenticated",
|
|
520
|
+
principal: delegated.member,
|
|
521
|
+
caller: {
|
|
522
|
+
kind: "runtime",
|
|
523
|
+
subjectId: delegated.member.id,
|
|
524
|
+
delegatedBy: { id: client.id, account: delegated.account },
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
});
|
|
528
|
+
}
|
|
481
529
|
/**
|
|
482
530
|
* The workflow user a verified runtime caller acts as while it runs a task a workflow handed it:
|
|
483
531
|
* the task's secret names it, never the caller. Refused on a route that does not accept tasks, and
|
|
@@ -571,7 +619,15 @@ export function authenticate(credential, verifyToken, options = {}) {
|
|
|
571
619
|
};
|
|
572
620
|
}
|
|
573
621
|
if (token.startsWith(API_KEY_PREFIX)) {
|
|
574
|
-
const
|
|
622
|
+
const resolved = backend.resolveApiKeyCredential === undefined
|
|
623
|
+
? yield* backend
|
|
624
|
+
.resolveApiKey(credential)
|
|
625
|
+
.pipe(Effect.map((principal) => principal === undefined ? undefined : { principal, delegation: false }))
|
|
626
|
+
: yield* backend.resolveApiKeyCredential(credential);
|
|
627
|
+
if (resolved?.delegation === true) {
|
|
628
|
+
return yield* delegatedMember(resolved.principal, options.runtime);
|
|
629
|
+
}
|
|
630
|
+
const principal = resolved?.principal;
|
|
575
631
|
return principal === undefined
|
|
576
632
|
? { status: "rejected" }
|
|
577
633
|
: {
|
|
@@ -11,7 +11,23 @@ export type VerifiedCaller = {
|
|
|
11
11
|
} | {
|
|
12
12
|
readonly kind: "runtime" | "service" | "member" | "workload";
|
|
13
13
|
readonly subjectId: string;
|
|
14
|
+
/**
|
|
15
|
+
* Set only for a runtime caller that authenticated with an API key with delegation: the
|
|
16
|
+
* key's user, and the member's account the request acts through. Its runtime metadata must
|
|
17
|
+
* come from that account.
|
|
18
|
+
*/
|
|
19
|
+
readonly delegatedBy?: DelegatingClient;
|
|
14
20
|
};
|
|
21
|
+
/** An external agent runtime acting for a member with an API key with delegation. */
|
|
22
|
+
export interface DelegatingClient {
|
|
23
|
+
/** The key's user: the external runtime the workspace trusts. */
|
|
24
|
+
readonly id: string;
|
|
25
|
+
/** The member's live chat account the request acts through. */
|
|
26
|
+
readonly account: {
|
|
27
|
+
readonly provider: string;
|
|
28
|
+
readonly subject: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
15
31
|
export type CallerContext = VerifiedCaller | {
|
|
16
32
|
readonly kind: "unverified";
|
|
17
33
|
};
|
|
@@ -14,6 +14,12 @@ declare const RuntimeEnvelope: Schema.Struct<{
|
|
|
14
14
|
readonly reply_to_message_id: Schema.optionalKey<Schema.String>;
|
|
15
15
|
readonly callback_query_id: Schema.optionalKey<Schema.String>;
|
|
16
16
|
readonly sender: Schema.optionalKey<Schema.String>;
|
|
17
|
+
readonly location: Schema.optionalKey<Schema.Struct<{
|
|
18
|
+
readonly latitude: Schema.Number;
|
|
19
|
+
readonly longitude: Schema.Number;
|
|
20
|
+
readonly horizontal_accuracy: Schema.optionalKey<Schema.Number>;
|
|
21
|
+
readonly live_period: Schema.optionalKey<Schema.Int>;
|
|
22
|
+
}>>;
|
|
17
23
|
readonly attachments: Schema.optionalKey<Schema.$Array<Schema.Struct<{
|
|
18
24
|
readonly file_id: Schema.String;
|
|
19
25
|
readonly file_unique_id: Schema.optionalKey<Schema.String>;
|
|
@@ -48,6 +54,12 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
|
|
|
48
54
|
readonly reply_to_message_id?: string | undefined;
|
|
49
55
|
readonly callback_query_id?: string | undefined;
|
|
50
56
|
readonly sender?: string | undefined;
|
|
57
|
+
readonly location?: {
|
|
58
|
+
readonly latitude: number;
|
|
59
|
+
readonly longitude: number;
|
|
60
|
+
readonly horizontal_accuracy?: number | undefined;
|
|
61
|
+
readonly live_period?: number | undefined;
|
|
62
|
+
} | undefined;
|
|
51
63
|
readonly attachments?: readonly {
|
|
52
64
|
readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
|
|
53
65
|
readonly file_id: string;
|
|
@@ -57,7 +69,7 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
|
|
|
57
69
|
}[] | undefined;
|
|
58
70
|
} | {
|
|
59
71
|
readonly kind: "group" | "private";
|
|
60
|
-
readonly provider: "
|
|
72
|
+
readonly provider: "whatsapp" | "slack";
|
|
61
73
|
readonly chat_id: string;
|
|
62
74
|
readonly thread_id: string;
|
|
63
75
|
readonly message_id?: string | undefined;
|
|
@@ -94,6 +106,12 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
|
|
|
94
106
|
readonly reply_to_message_id?: string | undefined;
|
|
95
107
|
readonly callback_query_id?: string | undefined;
|
|
96
108
|
readonly sender?: string | undefined;
|
|
109
|
+
readonly location?: {
|
|
110
|
+
readonly latitude: number;
|
|
111
|
+
readonly longitude: number;
|
|
112
|
+
readonly horizontal_accuracy?: number | undefined;
|
|
113
|
+
readonly live_period?: number | undefined;
|
|
114
|
+
} | undefined;
|
|
97
115
|
readonly attachments?: readonly {
|
|
98
116
|
readonly kind: "photo" | "document" | "voice" | "audio" | "video" | "video_note" | "sticker" | "animation";
|
|
99
117
|
readonly file_id: string;
|
|
@@ -103,7 +121,7 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
|
|
|
103
121
|
}[] | undefined;
|
|
104
122
|
} | {
|
|
105
123
|
readonly kind: "group" | "private";
|
|
106
|
-
readonly provider: "
|
|
124
|
+
readonly provider: "whatsapp" | "slack";
|
|
107
125
|
readonly chat_id: string;
|
|
108
126
|
readonly thread_id: string;
|
|
109
127
|
readonly message_id?: string | undefined;
|
|
@@ -34,6 +34,16 @@ export function consumeChatEnvelope(args, caller) {
|
|
|
34
34
|
message: "The runtime operation does not match its call.",
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
// An external runtime acting with an API key with delegation vouches only for messages of the
|
|
38
|
+
// account it acts through: the source names that account as its sender, on its provider.
|
|
39
|
+
if (caller.delegatedBy !== undefined &&
|
|
40
|
+
parsed.source !== undefined &&
|
|
41
|
+
(parsed.source.provider !== caller.delegatedBy.account.provider ||
|
|
42
|
+
parsed.source.sender !== caller.delegatedBy.account.subject)) {
|
|
43
|
+
return yield* new PermissionDenied({
|
|
44
|
+
message: "The runtime source must name the member's own account as its sender, on its provider.",
|
|
45
|
+
});
|
|
46
|
+
}
|
|
37
47
|
return { input, envelope: parsed };
|
|
38
48
|
});
|
|
39
49
|
}
|
|
@@ -471,6 +471,15 @@ declare const OntologyBackend_base: Context.ServiceClass<OntologyBackend, "@segm
|
|
|
471
471
|
readonly checkSignIn: (email: string) => Effect.Effect<SignInCheck>;
|
|
472
472
|
/** The user holding an `ssk_` key, or `undefined` for an unknown or revoked key. */
|
|
473
473
|
readonly resolveApiKey: (key: Redacted.Redacted<string>) => Effect.Effect<Principal | undefined>;
|
|
474
|
+
/**
|
|
475
|
+
* The user holding an `ssk_` key and whether the key acts with delegation, only for the member
|
|
476
|
+
* each request names; `undefined` for an unknown or revoked key. Without it every key acts with
|
|
477
|
+
* its own user's roles, through {@link resolveApiKey}.
|
|
478
|
+
*/
|
|
479
|
+
readonly resolveApiKeyCredential?: (key: Redacted.Redacted<string>) => Effect.Effect<{
|
|
480
|
+
readonly principal: Principal;
|
|
481
|
+
readonly delegation: boolean;
|
|
482
|
+
} | undefined>;
|
|
474
483
|
/** The manifest hash recorded in the `_ontology` catalog table, or `undefined` before the first. */
|
|
475
484
|
readonly appliedHash: Effect.Effect<string | undefined>;
|
|
476
485
|
readonly replicationEnabled?: Effect.Effect<boolean>;
|
|
@@ -423,9 +423,15 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
423
423
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
424
424
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
425
425
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
426
|
+
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
427
|
+
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
428
|
+
}>>;
|
|
429
|
+
readonly onSignUp: Schema.optionalKey<Schema.String>;
|
|
426
430
|
}>, {
|
|
427
431
|
readonly onNewUser: "on_new_user";
|
|
428
432
|
readonly codeLink: "code_link";
|
|
433
|
+
readonly signUp: "sign_up";
|
|
434
|
+
readonly onSignUp: "on_sign_up";
|
|
429
435
|
}>>;
|
|
430
436
|
readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
|
|
431
437
|
readonly subject: Schema.String;
|
|
@@ -658,9 +664,15 @@ export declare const Catalog: Schema.decodeTo<Schema.Struct<{
|
|
|
658
664
|
readonly channels: Schema.optionalKey<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
659
665
|
readonly onNewUser: Schema.optionalKey<Schema.String>;
|
|
660
666
|
readonly codeLink: Schema.optionalKey<Schema.Boolean>;
|
|
667
|
+
readonly signUp: Schema.optionalKey<Schema.Struct<{
|
|
668
|
+
readonly channels: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
669
|
+
}>>;
|
|
670
|
+
readonly onSignUp: Schema.optionalKey<Schema.String>;
|
|
661
671
|
}>, {
|
|
662
672
|
readonly onNewUser: "on_new_user";
|
|
663
673
|
readonly codeLink: "code_link";
|
|
674
|
+
readonly signUp: "sign_up";
|
|
675
|
+
readonly onSignUp: "on_sign_up";
|
|
664
676
|
}>>>;
|
|
665
677
|
readonly emails: Schema.toEncoded<Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
|
|
666
678
|
readonly subject: Schema.String;
|
package/dist/sign-in.d.ts
CHANGED
|
@@ -7,9 +7,34 @@ export declare const SIGN_IN_POLICIES: readonly ["invited", "open"];
|
|
|
7
7
|
export type SignInPolicy = (typeof SIGN_IN_POLICIES)[number];
|
|
8
8
|
/** An internal app is closed by default: a person enters by invitation. */
|
|
9
9
|
export declare const DEFAULT_SIGN_IN_POLICY: SignInPolicy;
|
|
10
|
-
/** Channels
|
|
10
|
+
/** Channels `signIn.channels` can open; `signUp` replaces it. */
|
|
11
11
|
export declare const CHANNEL_PROVIDERS: readonly ["telegram"];
|
|
12
12
|
export type ChannelProvider = (typeof CHANNEL_PROVIDERS)[number];
|
|
13
|
+
/**
|
|
14
|
+
* The channels a stranger may sign up through. `email` is sign-in by email code in the app; the
|
|
15
|
+
* others are a first private message to the agent, or opening the Telegram Mini App.
|
|
16
|
+
*/
|
|
17
|
+
export declare const SIGN_UP_CHANNELS: readonly ["email", "telegram", "whatsapp"];
|
|
18
|
+
export type SignUpChannel = (typeof SIGN_UP_CHANNELS)[number];
|
|
19
|
+
/** The sign-up channels a person reaches through a chat, which need a matching `chat` adapter. */
|
|
20
|
+
export declare const SIGN_UP_CHAT_CHANNELS: ReadonlyArray<SignUpChannel>;
|
|
21
|
+
export declare function isSignUpChannel(value: unknown): value is SignUpChannel;
|
|
22
|
+
/**
|
|
23
|
+
* Where a stranger may become a user, and the roles they are given. A channel not listed admits
|
|
24
|
+
* only invited or paired people. A user created by sign-up holds exactly these roles, granted like
|
|
25
|
+
* any other and revocable one person at a time, and never the `member` baseline of invited people.
|
|
26
|
+
*/
|
|
27
|
+
export interface SignUpOptions<R = unknown> {
|
|
28
|
+
readonly channels: ReadonlyArray<SignUpChannel>;
|
|
29
|
+
/** Declared roles, as role objects or names; an empty list gives nothing beyond explicit grants. */
|
|
30
|
+
readonly roles: ReadonlyArray<R>;
|
|
31
|
+
/** Roles for a listed channel that differs from `roles`. */
|
|
32
|
+
readonly byChannel?: Readonly<Partial<Record<SignUpChannel, ReadonlyArray<R>>>>;
|
|
33
|
+
}
|
|
34
|
+
/** Sign-up as the manifest carries it: the wire names of the roles each open channel grants. */
|
|
35
|
+
export interface ResolvedSignUp {
|
|
36
|
+
readonly channels: Readonly<Partial<Record<SignUpChannel, ReadonlyArray<string>>>>;
|
|
37
|
+
}
|
|
13
38
|
/** How people become members of the app. Email and channel admission are independent. */
|
|
14
39
|
export interface SignInOptions {
|
|
15
40
|
readonly policy: SignInPolicy;
|
|
@@ -25,6 +50,12 @@ export interface SignInOptions {
|
|
|
25
50
|
*/
|
|
26
51
|
readonly codeLink?: boolean;
|
|
27
52
|
}
|
|
53
|
+
/** The sign-in options of a checked ontology, with the sign-up its definition declares. */
|
|
54
|
+
export interface ResolvedSignInOptions extends SignInOptions {
|
|
55
|
+
readonly signUp?: ResolvedSignUp;
|
|
56
|
+
/** Wire name of the idempotent, input-free action run as each user created by sign-up. */
|
|
57
|
+
readonly onSignUp?: string;
|
|
58
|
+
}
|
|
28
59
|
/**
|
|
29
60
|
* How a person signs in with an address. `code`: a six-digit code, for a member who has signed in
|
|
30
61
|
* with Neon Auth before, so their Neon Auth account exists. `link`: an emailed sign-in link, for
|
package/dist/sign-in.js
CHANGED
|
@@ -6,8 +6,19 @@
|
|
|
6
6
|
export const SIGN_IN_POLICIES = ["invited", "open"];
|
|
7
7
|
/** An internal app is closed by default: a person enters by invitation. */
|
|
8
8
|
export const DEFAULT_SIGN_IN_POLICY = "invited";
|
|
9
|
-
|
|
9
|
+
// @legacy ontology.legacy-channel-admission
|
|
10
|
+
/** Channels `signIn.channels` can open; `signUp` replaces it. */
|
|
10
11
|
export const CHANNEL_PROVIDERS = ["telegram"];
|
|
12
|
+
/**
|
|
13
|
+
* The channels a stranger may sign up through. `email` is sign-in by email code in the app; the
|
|
14
|
+
* others are a first private message to the agent, or opening the Telegram Mini App.
|
|
15
|
+
*/
|
|
16
|
+
export const SIGN_UP_CHANNELS = ["email", "telegram", "whatsapp"];
|
|
17
|
+
/** The sign-up channels a person reaches through a chat, which need a matching `chat` adapter. */
|
|
18
|
+
export const SIGN_UP_CHAT_CHANNELS = ["telegram", "whatsapp"];
|
|
19
|
+
export function isSignUpChannel(value) {
|
|
20
|
+
return SIGN_UP_CHANNELS.includes(value);
|
|
21
|
+
}
|
|
11
22
|
/**
|
|
12
23
|
* How a person signs in with an address. `code`: a six-digit code, for a member who has signed in
|
|
13
24
|
* with Neon Auth before, so their Neon Auth account exists. `link`: an emailed sign-in link, for
|
|
@@ -33,6 +33,17 @@ export interface AttachmentCaller {
|
|
|
33
33
|
readonly sessionId?: string;
|
|
34
34
|
/** Trusted user boundary; never accepted from agent tool arguments. */
|
|
35
35
|
readonly access?: "member";
|
|
36
|
+
/**
|
|
37
|
+
* Set when an external runtime acts with an API key with delegation: the key's user and the
|
|
38
|
+
* member's account it acts through, which its runtime metadata must name as the sender.
|
|
39
|
+
*/
|
|
40
|
+
readonly delegatedBy?: {
|
|
41
|
+
readonly id: string;
|
|
42
|
+
readonly account: {
|
|
43
|
+
readonly provider: string;
|
|
44
|
+
readonly subject: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
36
47
|
}
|
|
37
48
|
export interface ReceiveAttachment {
|
|
38
49
|
readonly source: (typeof ATTACHMENT_SOURCES)[number];
|
package/dist/user-identity.d.ts
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
/** How a sign-in identity came to be, as the `origin` property stores it. */
|
|
2
|
-
export declare const USER_IDENTITY_ORIGINS: readonly ["invite", "sign_in", "link", "pairing", "channel"];
|
|
2
|
+
export declare const USER_IDENTITY_ORIGINS: readonly ["invite", "sign_in", "link", "pairing", "channel", "attach"];
|
|
3
3
|
export type UserIdentityOrigin = (typeof USER_IDENTITY_ORIGINS)[number];
|
|
4
|
+
/**
|
|
5
|
+
* The chat providers whose accounts an administrator may attach to a member with
|
|
6
|
+
* `user_identity.attach`: the providers the app's agent talks on.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ATTACHABLE_IDENTITY_PROVIDERS: readonly ["telegram", "whatsapp", "slack"];
|
|
9
|
+
export type AttachableIdentityProvider = (typeof ATTACHABLE_IDENTITY_PROVIDERS)[number];
|
|
4
10
|
/**
|
|
5
11
|
* The built-in record of every external account a member signs in or talks with: their Neon Auth
|
|
6
12
|
* account, their SegmentStream (OIDC) accounts and their channel accounts, such as Telegram. Every
|
|
7
|
-
* ontology includes it next to `User` and `AgentChat`. Only the platform writes it, with history
|
|
8
|
-
* no generated
|
|
9
|
-
* `
|
|
13
|
+
* ontology includes it next to `User` and `AgentChat`. Only the platform writes it, with history:
|
|
14
|
+
* no generated `create`, `update` or `delete` exists and no authored action writes it. Its two
|
|
15
|
+
* platform actions, `attach` and `revoke`, let an administrator attach a chat account to a member
|
|
16
|
+
* and revoke one. Reading it, attaching and revoking each need a permission that names it, such
|
|
17
|
+
* as `user_identity:read` or `user_identity:attach`: an entity wildcard (`*:read`, `*:*`) does not
|
|
18
|
+
* cover it.
|
|
10
19
|
*
|
|
11
20
|
* At most one live identity holds an account, and a member holds at most one live identity per
|
|
12
21
|
* provider other than `oidc`. Both are unique keys that hold a value only while the identity is
|
|
@@ -18,7 +27,7 @@ export declare const UserIdentity: import("./entity.js").DraftEntity<"user_ident
|
|
|
18
27
|
readonly subject: import("./property.js").Property<string, false, false>;
|
|
19
28
|
readonly username: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
|
|
20
29
|
readonly display: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
|
|
21
|
-
readonly origin: import("./property.js").Property<"link" | "invite" | "
|
|
30
|
+
readonly origin: import("./property.js").Property<"link" | "invite" | "attach" | "sign_in" | "channel" | "pairing", false, false>;
|
|
22
31
|
readonly revokedAt: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, false>>;
|
|
23
32
|
readonly accountKey: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, true>>;
|
|
24
33
|
readonly memberKey: import("effect/Schema").optionalKey<import("./property.js").Property<string, false, true>>;
|
package/dist/user-identity.js
CHANGED
|
@@ -2,13 +2,28 @@ import { entity } from "./entity.js";
|
|
|
2
2
|
import { p } from "./property.js";
|
|
3
3
|
import { rel } from "./relationship.js";
|
|
4
4
|
/** How a sign-in identity came to be, as the `origin` property stores it. */
|
|
5
|
-
export const USER_IDENTITY_ORIGINS = [
|
|
5
|
+
export const USER_IDENTITY_ORIGINS = [
|
|
6
|
+
"invite",
|
|
7
|
+
"sign_in",
|
|
8
|
+
"link",
|
|
9
|
+
"pairing",
|
|
10
|
+
"channel",
|
|
11
|
+
"attach",
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* The chat providers whose accounts an administrator may attach to a member with
|
|
15
|
+
* `user_identity.attach`: the providers the app's agent talks on.
|
|
16
|
+
*/
|
|
17
|
+
export const ATTACHABLE_IDENTITY_PROVIDERS = ["telegram", "whatsapp", "slack"];
|
|
6
18
|
/**
|
|
7
19
|
* The built-in record of every external account a member signs in or talks with: their Neon Auth
|
|
8
20
|
* account, their SegmentStream (OIDC) accounts and their channel accounts, such as Telegram. Every
|
|
9
|
-
* ontology includes it next to `User` and `AgentChat`. Only the platform writes it, with history
|
|
10
|
-
* no generated
|
|
11
|
-
* `
|
|
21
|
+
* ontology includes it next to `User` and `AgentChat`. Only the platform writes it, with history:
|
|
22
|
+
* no generated `create`, `update` or `delete` exists and no authored action writes it. Its two
|
|
23
|
+
* platform actions, `attach` and `revoke`, let an administrator attach a chat account to a member
|
|
24
|
+
* and revoke one. Reading it, attaching and revoking each need a permission that names it, such
|
|
25
|
+
* as `user_identity:read` or `user_identity:attach`: an entity wildcard (`*:read`, `*:*`) does not
|
|
26
|
+
* cover it.
|
|
12
27
|
*
|
|
13
28
|
* At most one live identity holds an account, and a member holds at most one live identity per
|
|
14
29
|
* provider other than `oidc`. Both are unique keys that hold a value only while the identity is
|
|
@@ -20,7 +35,8 @@ export const UserIdentity = entity("user_identity", {
|
|
|
20
35
|
plural: "Sign-in identities",
|
|
21
36
|
title: "subject",
|
|
22
37
|
description: "An external account a member signs in or talks with: their email sign-in, a SegmentStream " +
|
|
23
|
-
"account, or a chat account such as Telegram. The platform records them;
|
|
38
|
+
"account, or a chat account such as Telegram. The platform records them; an administrator " +
|
|
39
|
+
"may attach a member's chat account and revoke one.",
|
|
24
40
|
writes: "actions",
|
|
25
41
|
properties: {
|
|
26
42
|
provider: p.text({
|
|
@@ -70,6 +86,10 @@ export const UserIdentity = entity("user_identity", {
|
|
|
70
86
|
value: "channel",
|
|
71
87
|
description: "An open chat channel created the member for the chat account.",
|
|
72
88
|
},
|
|
89
|
+
{
|
|
90
|
+
value: "attach",
|
|
91
|
+
description: "An administrator attached the chat account to the member.",
|
|
92
|
+
},
|
|
73
93
|
], { managed: true, description: "How the account came to belong to the member." }),
|
|
74
94
|
revokedAt: p.timestamp({
|
|
75
95
|
optional: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.96.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",
|