@segmentstream/ontology 0.205.0 → 0.207.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 +8 -0
- package/dist/runtime-source.d.ts +2 -0
- package/dist/runtime-source.js +3 -0
- package/dist/service/channel/telegram-pairing.d.ts +2 -2
- package/dist/service/channel/telegram-pairing.js +32 -8
- package/dist/service/chat/envelope.d.ts +3 -0
- package/dist/service/config.d.ts +2 -0
- package/dist/service/mcp/server.js +6 -1
- package/dist/service/service.js +5 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.207.0
|
|
4
|
+
|
|
5
|
+
Ontology actions can read the verified original Telegram message time in `context.runtime.source.sent_at`, including when delivery was delayed or the sender edited the message. The agent sends the field only to ontologies that advertise support.
|
|
6
|
+
|
|
7
|
+
## 0.206.0
|
|
8
|
+
|
|
9
|
+
A Telegram Mini App can opt into pairing the original sender with an invited workspace email account, with the same signed browser challenge as Cloud sign-in.
|
|
10
|
+
|
|
3
11
|
## 0.205.0
|
|
4
12
|
|
|
5
13
|
Report database query counts, elapsed query time and activity intervals for ontology requests and workflow steps. Upgrade and deploy the ontology to make its observations available in workspace usage diagnostics.
|
package/dist/runtime-source.d.ts
CHANGED
|
@@ -12,6 +12,8 @@ export declare const RuntimeSource: Schema.Union<readonly [Schema.Struct<{
|
|
|
12
12
|
readonly chat_id: Schema.String;
|
|
13
13
|
readonly thread_id: Schema.String;
|
|
14
14
|
readonly message_id: Schema.optionalKey<Schema.String>;
|
|
15
|
+
/** Original send time from the provider. Edits retain the original time. */
|
|
16
|
+
readonly sent_at: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
|
|
15
17
|
readonly reply_to_message_id: Schema.optionalKey<Schema.String>;
|
|
16
18
|
readonly callback_query_id: Schema.optionalKey<Schema.String>;
|
|
17
19
|
readonly sender: Schema.optionalKey<Schema.String>;
|
package/dist/runtime-source.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
|
+
import { p } from "./property.js";
|
|
2
3
|
import { ChatChannelName } from "./chat-channel.js";
|
|
3
4
|
const Id = Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(512));
|
|
4
5
|
/**
|
|
@@ -24,6 +25,8 @@ const TelegramRuntimeSource = Schema.Struct({
|
|
|
24
25
|
chat_id: Id,
|
|
25
26
|
thread_id: Schema.String.check(Schema.isMaxLength(512)),
|
|
26
27
|
message_id: Schema.optionalKey(Id),
|
|
28
|
+
/** Original send time from the provider. Edits retain the original time. */
|
|
29
|
+
sent_at: Schema.optionalKey(p.timestamp()),
|
|
27
30
|
reply_to_message_id: Schema.optionalKey(Id),
|
|
28
31
|
callback_query_id: Schema.optionalKey(Id),
|
|
29
32
|
sender: Schema.optionalKey(Id),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type TokenVerifier } from "../authentication.js";
|
|
1
|
+
import { type SessionExchange, type TokenVerifier } from "../authentication.js";
|
|
2
2
|
import type { OntologyServiceConfig } from "../config.js";
|
|
3
3
|
import type { ConnectionTransportFactory } from "../connections.js";
|
|
4
4
|
import { RequestId } from "../errors.js";
|
|
@@ -6,4 +6,4 @@ import { OntologyBackend } from "../runtime-contract.js";
|
|
|
6
6
|
import type { ChannelAppProvider } from "./provider.js";
|
|
7
7
|
/** A public button names the request. Telegram proves its original sender, then signs
|
|
8
8
|
* a fresh challenge in the browser that completed Cloud login. Neither link is a credential. */
|
|
9
|
-
export declare function telegramPairingLayer(config: OntologyServiceConfig, connections: ConnectionTransportFactory, telegram: ChannelAppProvider, connection: string, verifyToken: TokenVerifier): import("effect/Layer").Layer<never, never, OntologyBackend | import("effect/unstable/http/HttpRouter").HttpRouter | import("effect/unstable/http/HttpRouter").Request<"Requires", RequestId> | import("effect/unstable/http/HttpRouter").Request<"Error", import("effect/unstable/http/HttpServerError").HttpServerError>>;
|
|
9
|
+
export declare function telegramPairingLayer(config: OntologyServiceConfig, connections: ConnectionTransportFactory, telegram: ChannelAppProvider, connection: string, verifyToken: TokenVerifier, exchangeEmailSession?: SessionExchange): import("effect/Layer").Layer<never, never, OntologyBackend | import("effect/unstable/http/HttpRouter").HttpRouter | import("effect/unstable/http/HttpRouter").Request<"Requires", RequestId> | import("effect/unstable/http/HttpRouter").Request<"Error", import("effect/unstable/http/HttpServerError").HttpServerError>>;
|
|
@@ -2,7 +2,7 @@ import { randomBytes, randomUUID } from "node:crypto";
|
|
|
2
2
|
import { Effect, Redacted } from "effect";
|
|
3
3
|
import { HttpServerResponse } from "effect/unstable/http";
|
|
4
4
|
import { use as routes } from "effect/unstable/http/HttpRouter";
|
|
5
|
-
import { CurrentPrincipal, sessionMayAuthenticate, withPrincipal, } from "../authentication.js";
|
|
5
|
+
import { CurrentPrincipal, NEON_AUTH_SESSION_COOKIE, sessionMayAuthenticate, withPrincipal, } from "../authentication.js";
|
|
6
6
|
import { FEDERATION_TOKEN_PREFIX } from "../../runtime/federation.js";
|
|
7
7
|
import { botUsername } from "../chat/providers/telegram.js";
|
|
8
8
|
import { identityToken } from "../operations.js";
|
|
@@ -11,7 +11,7 @@ import { clientAddress, fixedWindowLimiter } from "../rate-limit.js";
|
|
|
11
11
|
import { OntologyBackend } from "../runtime-contract.js";
|
|
12
12
|
const UUID = "[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
|
|
13
13
|
const launch = new RegExp("^sslink_(" + UUID + ")$");
|
|
14
|
-
const finish = new RegExp("^
|
|
14
|
+
const finish = new RegExp("^ssverify(?:email)?_(" + UUID + ")_([A-Za-z0-9_-]{32})$");
|
|
15
15
|
const json = (status, body, cookie) => HttpServerResponse.jsonUnsafe(body, {
|
|
16
16
|
status,
|
|
17
17
|
headers: {
|
|
@@ -21,7 +21,7 @@ const json = (status, body, cookie) => HttpServerResponse.jsonUnsafe(body, {
|
|
|
21
21
|
});
|
|
22
22
|
/** A public button names the request. Telegram proves its original sender, then signs
|
|
23
23
|
* a fresh challenge in the browser that completed Cloud login. Neither link is a credential. */
|
|
24
|
-
export function telegramPairingLayer(config, connections, telegram, connection, verifyToken) {
|
|
24
|
+
export function telegramPairingLayer(config, connections, telegram, connection, verifyToken, exchangeEmailSession) {
|
|
25
25
|
const suffix = config.workspaceId.replace(/[^A-Za-z0-9_-]/g, "_");
|
|
26
26
|
const cookieName = (id) => "__Host-ss_telegram_link." + suffix + "." + id;
|
|
27
27
|
const cookie = (id, value, age) => cookieName(id) + "=" + value + "; Secure; HttpOnly; SameSite=Lax; Path=/; Max-Age=" + age;
|
|
@@ -67,26 +67,50 @@ export function telegramPairingLayer(config, connections, telegram, connection,
|
|
|
67
67
|
if (!pairing) {
|
|
68
68
|
return json(403, { error: "pairing_unavailable" });
|
|
69
69
|
}
|
|
70
|
+
// Telegram signs the chosen method along with the challenge on the second launch.
|
|
71
|
+
const email = initial
|
|
72
|
+
? request.headers["x-segmentstream-pairing-method"] === "email"
|
|
73
|
+
: start.startsWith("ssverifyemail_");
|
|
74
|
+
if (email && !exchangeEmailSession) {
|
|
75
|
+
return json(403, { error: "email_pairing_unavailable" });
|
|
76
|
+
}
|
|
70
77
|
if (initial) {
|
|
71
78
|
const username = yield* botUsername(transport, connection);
|
|
72
79
|
if (!username) {
|
|
73
80
|
return json(503, { error: "bot_unavailable" });
|
|
74
81
|
}
|
|
75
82
|
const nonce = randomBytes(24).toString("base64url");
|
|
76
|
-
const continuation = "ssverify_" + id + "_" + nonce;
|
|
83
|
+
const continuation = (email ? "ssverifyemail_" : "ssverify_") + id + "_" + nonce;
|
|
77
84
|
return json(200, { reopen: "https://t.me/" + username + "?startapp=" + continuation }, cookie(id, continuation, 600));
|
|
78
85
|
}
|
|
79
86
|
if (request.cookies[cookieName(id)] !== start) {
|
|
80
87
|
return json(403, { error: "browser_mismatch" });
|
|
81
88
|
}
|
|
82
|
-
|
|
83
|
-
if (
|
|
89
|
+
let token = request.cookies["__Host-ss_oidc_session." + suffix];
|
|
90
|
+
if (email && exchangeEmailSession) {
|
|
91
|
+
const session = request.cookies[NEON_AUTH_SESSION_COOKIE];
|
|
92
|
+
if (!session) {
|
|
93
|
+
return json(401, { error: "email_login_required" });
|
|
94
|
+
}
|
|
95
|
+
const proof = yield* Effect.promise(() => exchangeEmailSession(Redacted.make(session), request.headers.origin));
|
|
96
|
+
if (proof.status === "unavailable") {
|
|
97
|
+
return json(503, { error: "sign_in_unavailable" });
|
|
98
|
+
}
|
|
99
|
+
if (proof.status !== "token") {
|
|
100
|
+
return json(401, { error: "email_login_required" });
|
|
101
|
+
}
|
|
102
|
+
token = proof.token;
|
|
103
|
+
}
|
|
104
|
+
if (!token || (!email && !token.startsWith(FEDERATION_TOKEN_PREFIX))) {
|
|
84
105
|
return json(401, { error: "cloud_login_required" });
|
|
85
106
|
}
|
|
86
107
|
return yield* withPrincipal(Redacted.make(token), verifyToken, backend, Effect.gen(function* () {
|
|
87
108
|
const member = yield* CurrentPrincipal;
|
|
88
|
-
if (member.kind !== "member" ||
|
|
89
|
-
|
|
109
|
+
if (member.kind !== "member" ||
|
|
110
|
+
member.authenticatedVia !== (email ? "neon-auth" : "oidc")) {
|
|
111
|
+
return json(403, {
|
|
112
|
+
error: email ? "email_login_required" : "cloud_login_required",
|
|
113
|
+
});
|
|
90
114
|
}
|
|
91
115
|
const linked = yield* store
|
|
92
116
|
.approvePairing({
|
|
@@ -13,6 +13,7 @@ declare const RuntimeEnvelope: Schema.Struct<{
|
|
|
13
13
|
readonly chat_id: Schema.String;
|
|
14
14
|
readonly thread_id: Schema.String;
|
|
15
15
|
readonly message_id: Schema.optionalKey<Schema.String>;
|
|
16
|
+
readonly sent_at: Schema.optionalKey<import("../../property.js").Property<string, false, false>>;
|
|
16
17
|
readonly reply_to_message_id: Schema.optionalKey<Schema.String>;
|
|
17
18
|
readonly callback_query_id: Schema.optionalKey<Schema.String>;
|
|
18
19
|
readonly sender: Schema.optionalKey<Schema.String>;
|
|
@@ -61,6 +62,7 @@ declare const CurrentChatCall_base: Context.ServiceClass<CurrentChatCall, "@segm
|
|
|
61
62
|
} | undefined;
|
|
62
63
|
readonly channel?: string | undefined;
|
|
63
64
|
readonly message_id?: string | undefined;
|
|
65
|
+
readonly sent_at?: string | undefined;
|
|
64
66
|
readonly reply_to_message_id?: string | undefined;
|
|
65
67
|
readonly callback_query_id?: string | undefined;
|
|
66
68
|
readonly sender?: string | undefined;
|
|
@@ -115,6 +117,7 @@ export declare function consumeChatEnvelope(args: Readonly<Record<string, unknow
|
|
|
115
117
|
} | undefined;
|
|
116
118
|
readonly channel?: string | undefined;
|
|
117
119
|
readonly message_id?: string | undefined;
|
|
120
|
+
readonly sent_at?: string | undefined;
|
|
118
121
|
readonly reply_to_message_id?: string | undefined;
|
|
119
122
|
readonly callback_query_id?: string | undefined;
|
|
120
123
|
readonly sender?: string | undefined;
|
package/dist/service/config.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ export interface OntologyEnvironment {
|
|
|
69
69
|
/** Explicit Mini App exchange opt-in; omitted means no exchange route. */
|
|
70
70
|
readonly miniApp?: {
|
|
71
71
|
readonly testPublicKeyHex?: string;
|
|
72
|
+
/** Offer verified workspace email sessions when linking a Telegram sender. */
|
|
73
|
+
readonly emailPairing?: boolean;
|
|
72
74
|
};
|
|
73
75
|
};
|
|
74
76
|
};
|
|
@@ -694,7 +694,12 @@ function dispatch(server, message, request) {
|
|
|
694
694
|
// The agent runtime learns that tool calls accept its chat source, and from which
|
|
695
695
|
// channels, without listing the catalog. The `me` tool keeps its `_meta` marker for
|
|
696
696
|
// older agents.
|
|
697
|
-
experimental: {
|
|
697
|
+
experimental: {
|
|
698
|
+
[RUNTIME_SOURCE_META]: {
|
|
699
|
+
providers: [...RUNTIME_SOURCE_PROVIDERS],
|
|
700
|
+
fields: ["telegram.sent_at"],
|
|
701
|
+
},
|
|
702
|
+
},
|
|
698
703
|
},
|
|
699
704
|
serverInfo: {
|
|
700
705
|
name: "segmentstream-ontology",
|
package/dist/service/service.js
CHANGED
|
@@ -565,8 +565,11 @@ export function createOntologyService(ontology, config) {
|
|
|
565
565
|
});
|
|
566
566
|
const application = Layer.mergeAll(channelApps.length > 0
|
|
567
567
|
? Layer.merge(channelSessionLayer(config), channelSignInLayer(channelApps, config, connections))
|
|
568
|
-
: Layer.empty, !preview &&
|
|
569
|
-
|
|
568
|
+
: Layer.empty, !preview &&
|
|
569
|
+
telegram?.miniApp &&
|
|
570
|
+
telegramConnection &&
|
|
571
|
+
(federationConfig || (telegram.miniApp.emailPairing && exchangeSession))
|
|
572
|
+
? telegramPairingLayer(config, connections, telegramAppProvider(telegramConnection, testKey), telegramConnection, verifyToken, telegram.miniApp.emailPairing ? exchangeSession : undefined)
|
|
570
573
|
: Layer.empty, federationLayer(federationConfig, verifyToken, { ontology, browserRevision }), routes, withoutAgent
|
|
571
574
|
? Layer.empty
|
|
572
575
|
: chatRoutes({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/ontology",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.207.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",
|