@segmentstream/agent 0.45.0 → 0.47.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.
Files changed (71) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +25 -3
  3. package/dist/_chunks/{build-metadata-s0t4FPPK.mjs → build-metadata-5S6uTvyu.mjs} +1 -1
  4. package/dist/_chunks/{inbound-request-CK0QqEOP.mjs → inbound-request-B3RhCuOw.mjs} +6 -11
  5. package/dist/_chunks/{principal-BXvelsZk.mjs → principal-Dzs8hUDB.mjs} +1 -1
  6. package/dist/extension/config.d.ts +10 -0
  7. package/dist/extension/config.mjs +11 -0
  8. package/dist/extension/extension.d.ts +5 -0
  9. package/dist/extension/extension.mjs +2 -1
  10. package/dist/extension/hooks/authorization.mjs +1 -1
  11. package/dist/extension/hooks/workspace-source.d.ts +6 -0
  12. package/dist/extension/hooks/workspace-source.mjs +10 -0
  13. package/dist/extension/instructions/persona.mjs +1 -1
  14. package/dist/extension/instructions/sandbox.mjs +16 -2
  15. package/dist/extension/lib/actor.mjs +6 -2
  16. package/dist/extension/lib/attachment-tools.mjs +1 -1
  17. package/dist/extension/lib/build-metadata.mjs +1 -1
  18. package/dist/extension/lib/chat-address.d.ts +1 -1
  19. package/dist/extension/lib/chat-address.mjs +2 -2
  20. package/dist/extension/lib/chat-context.mjs +1 -1
  21. package/dist/extension/lib/chat-recorder.mjs +12 -1
  22. package/dist/extension/lib/confirmations.mjs +1 -1
  23. package/dist/extension/lib/ontology-connection.mjs +8 -4
  24. package/dist/extension/lib/ontology-file-call.mjs +1 -1
  25. package/dist/extension/lib/ontology-tools.mjs +1 -1
  26. package/dist/extension/lib/review/hold.mjs +2 -2
  27. package/dist/extension/lib/review/reply.mjs +1 -1
  28. package/dist/extension/lib/role-skill.mjs +1 -1
  29. package/dist/extension/lib/runtime-envelope.mjs +1 -1
  30. package/dist/extension/lib/slack/attachments-send.mjs +1 -1
  31. package/dist/extension/lib/stored-files.mjs +1 -1
  32. package/dist/extension/lib/telegram/adapter.mjs +15 -28
  33. package/dist/extension/lib/telegram/app-links.d.ts +22 -0
  34. package/dist/extension/lib/telegram/app-links.mjs +27 -1
  35. package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
  36. package/dist/extension/lib/telegram/attachments-send.d.ts +3 -0
  37. package/dist/extension/lib/telegram/attachments-send.mjs +16 -4
  38. package/dist/extension/lib/telegram/bot.d.ts +17 -0
  39. package/dist/extension/lib/telegram/bot.mjs +21 -1
  40. package/dist/extension/lib/telegram/callbacks.mjs +2 -2
  41. package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
  42. package/dist/extension/lib/telegram/confirmations.mjs +2 -2
  43. package/dist/extension/lib/telegram/customer-text.mjs +1 -1
  44. package/dist/extension/lib/telegram/files.mjs +2 -2
  45. package/dist/extension/lib/telegram/health.mjs +1 -1
  46. package/dist/extension/lib/telegram/images.mjs +1 -1
  47. package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
  48. package/dist/extension/lib/telegram/inbound.mjs +2 -2
  49. package/dist/extension/lib/telegram/lifecycle.mjs +3 -3
  50. package/dist/extension/lib/telegram/media-policy.mjs +1 -1
  51. package/dist/extension/lib/telegram/principal.mjs +1 -1
  52. package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
  53. package/dist/extension/lib/telegram/silent.mjs +1 -1
  54. package/dist/extension/lib/telegram/structured.mjs +1 -1
  55. package/dist/extension/lib/telegram/turn-errors.mjs +2 -2
  56. package/dist/extension/lib/telegram/voice.mjs +1 -1
  57. package/dist/extension/lib/web/auth.d.ts +60 -0
  58. package/dist/extension/lib/web/auth.mjs +130 -0
  59. package/dist/extension/lib/web/channel.d.ts +15 -0
  60. package/dist/extension/lib/web/channel.mjs +18 -0
  61. package/dist/extension/lib/workspace-source.d.ts +130 -0
  62. package/dist/extension/lib/workspace-source.mjs +451 -0
  63. package/dist/extension/model.mjs +1 -1
  64. package/dist/extension/tools/attachments_promote.mjs +1 -1
  65. package/dist/extension/tools/attachments_send.mjs +3 -1
  66. package/dist/extension/tools/questions_ask.mjs +1 -1
  67. package/dist/extension/tools/workspace_source.d.ts +2 -0
  68. package/dist/extension/tools/workspace_source.mjs +44 -0
  69. package/dist/tools/index.d.ts +1 -0
  70. package/dist/tools/index.mjs +2 -1
  71. package/package.json +7 -4
@@ -10,7 +10,7 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
10
10
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
11
11
  import { handleWorkspaceCallback, isWorkspaceCallback } from "./callbacks.mjs";
12
12
  import { telegramText, withTelegramTexts } from "./texts.mjs";
13
- import { t as agentBuild } from "../../../_chunks/build-metadata-s0t4FPPK.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-5S6uTvyu.mjs";
14
14
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
15
  import { manifestOf } from "../../config.mjs";
16
16
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
@@ -23,11 +23,12 @@ import { chatArchive, topicContext } from "../chat-archive.mjs";
23
23
  import { captureRouteDecider, captureTelegramFetch, chatIdentities, recordGateDecision, telegramChatCapture } from "./chat-archive.mjs";
24
24
  import { runtimeTokenVerifier } from "../runtime-identity.mjs";
25
25
  import { runtimeToken } from "../runtime-token.mjs";
26
- import { botIdentityCache } from "./bot.mjs";
26
+ import { botIdentityCache, proxiedBotRequest, runtimeBotIdentity } from "./bot.mjs";
27
27
  import { handleConfirmationCallback, telegramConfirmationEvents } from "./confirmations.mjs";
28
28
  import { confirmationLocale } from "./confirmation-text.mjs";
29
- import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, o as currentLocale, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
30
- import { n as chatLanguage, o as telegramPrincipal } from "../../../_chunks/principal-BXvelsZk.mjs";
29
+ import { d as failureText, h as withDeliveryLocale, i as withReplacedText, m as safeTelegramFetch, n as currentInboundRequest, o as currentLocale, p as reportTelegramError, r as runInboundRequest, t as InboundRequest } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
30
+ import { telegramAppLinkContext } from "./app-links.mjs";
31
+ import { n as chatLanguage, o as telegramPrincipal } from "../../../_chunks/principal-Dzs8hUDB.mjs";
31
32
  import { gatewayImageDescriber } from "./images.mjs";
32
33
  import { gatewayMediaCapabilities, planMedia } from "./media-policy.mjs";
33
34
  import { agentChats } from "../chats.mjs";
@@ -122,19 +123,11 @@ function segmentstreamTelegram(options) {
122
123
  }
123
124
  return existing;
124
125
  }
125
- async function botRequest(method, body = {}) {
126
- const reply = await proxy().request({
127
- api: "bot",
128
- method: "POST",
129
- path: `/${method}`,
130
- headers: [["content-type", "application/json"]],
131
- body: new TextEncoder().encode(JSON.stringify(body))
132
- });
133
- return {
134
- ok: reply.status >= 200 && reply.status < 300,
135
- status: reply.status,
136
- body: JSON.parse(new TextDecoder().decode(reply.body))
137
- };
126
+ function botRequest(method, body) {
127
+ return proxiedBotRequest(proxy(), method, body);
128
+ }
129
+ function botIdentity() {
130
+ return runtimeBotIdentity(telegramSendScope(environment, settings().connection), bot);
138
131
  }
139
132
  function pairing() {
140
133
  identities ??= agentIdentities({
@@ -201,16 +194,10 @@ function segmentstreamTelegram(options) {
201
194
  api: {
202
195
  apiBaseUrl: TELEGRAM_PROXY_ORIGIN,
203
196
  fileBaseUrl: TELEGRAM_PROXY_ORIGIN,
204
- fetch: (input, init) => {
205
- const ownOrigins = telegramPreviewEnvironment(environment).appOrigins;
206
- return safeTelegramFetch(captureTelegramFetch(telegramProxyFetch(proxy(), telegramSendScope(environment, settings().connection)), archive, pairing), telegramSendScope(environment, settings().connection), {
207
- settings: settings(),
208
- ownOrigins
209
- }, settings().appLinks === "miniApp" ? {
210
- origins: [...ownOrigins, ...settings().additionalOwnOrigins ?? []],
211
- botUsername: async () => (await bot({ request: botRequest }))?.username
212
- } : void 0)(input, init);
213
- }
197
+ fetch: (input, init) => safeTelegramFetch(captureTelegramFetch(telegramProxyFetch(proxy(), telegramSendScope(environment, settings().connection)), archive, pairing), telegramSendScope(environment, settings().connection), {
198
+ settings: settings(),
199
+ ownOrigins: telegramPreviewEnvironment(environment).appOrigins
200
+ }, telegramAppLinkContext(settings(), environment, async () => (await botIdentity()({ request: botRequest }))?.username))(input, init)
214
201
  },
215
202
  credentials: {
216
203
  botToken: TELEGRAM_PLACEHOLDER_TOKEN,
@@ -300,7 +287,7 @@ function segmentstreamTelegram(options) {
300
287
  } : await capabilities(selected), options.models().imageDescription ?? null);
301
288
  },
302
289
  identities: chatIdentities(pairing()),
303
- bot,
290
+ bot: botIdentity(),
304
291
  decide: captureRouteDecider(decisionRouter({
305
292
  decide: options.decide,
306
293
  model: options.models().decision
@@ -19,6 +19,17 @@ export interface TelegramAppLinkContext {
19
19
  /** The bot's username, from a cached lookup; without one, links stay as they are. */
20
20
  readonly botUsername: () => Promise<string | undefined>;
21
21
  }
22
+ /** The Telegram channel settings that decide where links to the app open. */
23
+ export interface TelegramAppLinkSettings {
24
+ readonly appLinks?: string;
25
+ readonly additionalOwnOrigins?: readonly string[];
26
+ }
27
+ /**
28
+ * The context that opens a channel's links to the app in the Mini App, or `undefined` while they
29
+ * stay as written. Replies, edits and buttons through the delivery guard and the captions of the
30
+ * attachment tool use the same one, so both open the same links.
31
+ */
32
+ export declare function telegramAppLinkContext(settings: TelegramAppLinkSettings | null | undefined, environment: Readonly<Record<string, string | undefined>>, botUsername: () => Promise<string | undefined>): TelegramAppLinkContext | undefined;
22
33
  /**
23
34
  * Whether a link may open the app's page at `pathname`: a local path, also once decoded, that is
24
35
  * not an API, an asset, or a page where the member decides something.
@@ -37,3 +48,14 @@ export declare function miniAppLink(url: string, origins: ReadonlySet<string>, b
37
48
  * link as it is.
38
49
  */
39
50
  export declare function miniAppLinks(context: TelegramAppLinkContext, urls: Iterable<string>): Promise<ReadonlyMap<string, string>>;
51
+ /** `items` with each one whose `url` has a Mini App link in `links` pointing there instead. */
52
+ export declare function withMiniAppLinks<T>(items: T, links: ReadonlyMap<string, string>): T;
53
+ /**
54
+ * A message's preview options, kept on the page its first link was written as. Telegram previews
55
+ * the first link it delivers unless the options disable the preview or name a URL, so once that
56
+ * link opens in the Mini App it would preview the bot's `t.me` page. When `links`, the message's
57
+ * links as written in order, begin with one that `rewritten` maps, the options name it instead;
58
+ * options that disable the preview or already name a URL stay as they are, and any others are
59
+ * kept beside it.
60
+ */
61
+ export declare function originalLinkPreview(options: Readonly<Record<string, unknown>>, links: readonly string[], rewritten: ReadonlyMap<string, string>): Readonly<Record<string, unknown>>;
@@ -4,7 +4,14 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
+ import { telegramPreviewEnvironment } from "@segmentstream/ontology/telegram";
7
8
  const TELEGRAM_APP_LINKS = ["web", "miniApp"];
9
+ function telegramAppLinkContext(settings, environment, botUsername) {
10
+ return settings?.appLinks === "miniApp" ? {
11
+ origins: [...telegramPreviewEnvironment(environment).appOrigins, ...settings.additionalOwnOrigins ?? []],
12
+ botUsername
13
+ } : void 0;
14
+ }
8
15
  const START_PARAM_PREFIX = "p_";
9
16
  const MAXIMUM_START_PARAM_LENGTH = 512;
10
17
  const NOT_LINKED_PATHS = [
@@ -50,4 +57,23 @@ async function miniAppLinks(context, urls) {
50
57
  if (username === void 0 || !/^[A-Za-z0-9_]{1,64}$/u.test(username)) return new Map();
51
58
  return new Map(candidates.map((url) => [url, miniAppLink(url, origins, username)]));
52
59
  }
53
- export { TELEGRAM_APP_LINKS, isAppContentPage, miniAppLink, miniAppLinks, telegramStartParam };
60
+ function withMiniAppLinks(items, links) {
61
+ return links.size === 0 || !Array.isArray(items) ? items : items.map((item) => typeof item === "object" && item !== null && "url" in item && typeof item.url === "string" && links.has(item.url) ? {
62
+ ...item,
63
+ url: links.get(item.url)
64
+ } : item);
65
+ }
66
+ function originalLinkPreview(options, links, rewritten) {
67
+ const first = links[0];
68
+ if (first === void 0 || !rewritten.has(first)) return options;
69
+ const explicit = options.link_preview_options;
70
+ if (explicit !== void 0) return typeof explicit === "object" && explicit !== null && !Array.isArray(explicit) && !("is_disabled" in explicit && explicit.is_disabled === true) && !("url" in explicit && explicit.url !== void 0) ? {
71
+ ...options,
72
+ link_preview_options: {
73
+ ...explicit,
74
+ url: first
75
+ }
76
+ } : options;
77
+ return options.disable_web_page_preview === true ? options : { link_preview_options: { url: first } };
78
+ }
79
+ export { TELEGRAM_APP_LINKS, isAppContentPage, miniAppLink, miniAppLinks, originalLinkPreview, telegramAppLinkContext, telegramStartParam, withMiniAppLinks };
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { describableImage } from "./images.mjs";
8
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
8
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
9
9
  import { gateway, generateText } from "ai";
10
10
  const MAXIMUM_ROUTING_ATTACHMENT_BYTES = 5242880;
11
11
  const ROUTING_ATTACHMENT_TIMEOUT_MS = 15e3;
@@ -2,6 +2,7 @@ import type { SessionAuthContext } from "eve/context";
2
2
  import { type DocumentReference } from "../sent-files.js";
3
3
  import { type Environment } from "../environment.js";
4
4
  import { type RuntimeToken } from "../runtime-token.js";
5
+ import { type TelegramAppLinkSettings } from "./app-links.js";
5
6
  export declare const MAXIMUM_PHOTO_BYTES: number;
6
7
  export declare const MAXIMUM_DOCUMENT_BYTES: number;
7
8
  export type { DocumentReference } from "../sent-files.js";
@@ -29,6 +30,8 @@ interface SendOptions {
29
30
  readonly principal: SessionAuthContext | null;
30
31
  readonly sessionId: string;
31
32
  readonly connection: string | undefined;
33
+ /** The channel's settings for links to the app, which the caption's links follow. */
34
+ readonly appLinks?: TelegramAppLinkSettings | null;
32
35
  readonly environment?: Environment;
33
36
  readonly token?: RuntimeToken;
34
37
  readonly fetch?: typeof fetch;
@@ -12,10 +12,12 @@ import { transientFileStatus } from "../file-grant.mjs";
12
12
  import { StoredFileError, fetchStoredFile } from "../sent-files.mjs";
13
13
  import { appOrigin, channelsEnabled, proxyEnvironment } from "../environment.mjs";
14
14
  import { runtimeToken } from "../runtime-token.mjs";
15
- import "../../../_chunks/principal-BXvelsZk.mjs";
15
+ import "../../../_chunks/principal-Dzs8hUDB.mjs";
16
16
  import { confirmationLocale } from "./confirmation-text.mjs";
17
17
  import { inTelegramSendQueue, telegramSendScope } from "./send-queue.mjs";
18
- import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
18
+ import { d as failureText, f as formattingRefused, l as customerMessage, p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
19
+ import { miniAppLinks, telegramAppLinkContext, withMiniAppLinks } from "./app-links.mjs";
20
+ import { proxiedBotRequest, runtimeBotIdentity } from "./bot.mjs";
19
21
  import { TELEGRAM_PLACEHOLDER_TOKEN, TELEGRAM_PROXY_ORIGIN, telegramProxyFetch } from "./proxy-fetch.mjs";
20
22
  const MAXIMUM_PHOTO_BYTES = 10485760;
21
23
  const MAXIMUM_DOCUMENT_BYTES = 52428800;
@@ -103,12 +105,14 @@ async function sendAttachmentsInOrder(options) {
103
105
  };
104
106
  const fetchImpl = options.fetch ?? fetch;
105
107
  const origin = appOrigin(environment);
106
- const telegram = telegramProxyFetch(connectionProxy({
108
+ const scope = telegramSendScope(environment, options.connection);
109
+ const proxy = connectionProxy({
107
110
  environment: proxyEnvironment(environment),
108
111
  connection: options.connection,
109
112
  token,
110
113
  fetch: fetchImpl
111
- }), telegramSendScope(environment, options.connection));
114
+ });
115
+ const telegram = telegramProxyFetch(proxy, scope);
112
116
  const results = options.input.documentIds.map(({ id }) => ({
113
117
  id,
114
118
  filename: ""
@@ -187,6 +191,14 @@ async function sendAttachmentsInOrder(options) {
187
191
  });
188
192
  }
189
193
  let caption = options.input.caption === void 0 ? void 0 : customerMessage(options.input.caption, locale);
194
+ const appLinks = caption === void 0 ? void 0 : telegramAppLinkContext(options.appLinks, environment, async () => (await runtimeBotIdentity(scope)({ request: (method, body) => proxiedBotRequest(proxy, method, body) }))?.username);
195
+ if (caption !== void 0 && appLinks !== void 0) {
196
+ const links = await miniAppLinks(appLinks, caption.entities.flatMap((entity) => entity.url === void 0 ? [] : [entity.url]));
197
+ caption = {
198
+ text: caption.text,
199
+ entities: withMiniAppLinks(caption.entities, links)
200
+ };
201
+ }
190
202
  let cursor = 0;
191
203
  while (cursor < uploads.length) {
192
204
  const batch = [uploads[cursor++]];
@@ -1,4 +1,21 @@
1
1
  import type { TelegramHandle } from "eve/channels/telegram";
2
+ import type { ConnectionProxy } from "../connection-proxy.js";
2
3
  import type { BotIdentity } from "./router.js";
3
4
  export type BotIdentityLookup = (telegram: Pick<TelegramHandle, "request">) => Promise<BotIdentity | undefined>;
4
5
  export declare function botIdentityCache(now?: () => number): BotIdentityLookup;
6
+ /**
7
+ * A Bot API call outside any chat, through the connection proxy, for the bot identity cache when it
8
+ * is asked before an inbound message has filled it. The cache logs a failure, such as an answer
9
+ * that is not JSON, and asks again later.
10
+ */
11
+ export declare function proxiedBotRequest(proxy: ConnectionProxy, method: string, body?: Readonly<Record<string, unknown>>): Promise<{
12
+ ok: boolean;
13
+ status: number;
14
+ body: unknown;
15
+ }>;
16
+ /**
17
+ * The identity cache of the bot behind a send scope in this runtime. The Telegram channel puts its
18
+ * own cache here as it uses it (`own`), so the attachment tool reads the username the channel
19
+ * already holds; where the channel has not run yet, the tool keeps a cache for the scope itself.
20
+ */
21
+ export declare function runtimeBotIdentity(scope: string, own?: BotIdentityLookup): BotIdentityLookup;
@@ -44,4 +44,24 @@ function botIdentityCache(now = Date.now) {
44
44
  return identity;
45
45
  };
46
46
  }
47
- export { botIdentityCache };
47
+ async function proxiedBotRequest(proxy, method, body = {}) {
48
+ const reply = await proxy.request({
49
+ api: "bot",
50
+ method: "POST",
51
+ path: `/${method}`,
52
+ headers: [["content-type", "application/json"]],
53
+ body: new TextEncoder().encode(JSON.stringify(body))
54
+ });
55
+ return {
56
+ ok: reply.status >= 200 && reply.status < 300,
57
+ status: reply.status,
58
+ body: JSON.parse(new TextDecoder().decode(reply.body))
59
+ };
60
+ }
61
+ const runtimeIdentities = new Map();
62
+ function runtimeBotIdentity(scope, own) {
63
+ const lookup = own ?? runtimeIdentities.get(scope) ?? botIdentityCache();
64
+ runtimeIdentities.set(scope, lookup);
65
+ return lookup;
66
+ }
67
+ export { botIdentityCache, proxiedBotRequest, runtimeBotIdentity };
@@ -5,8 +5,8 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { object } from "../confirmation-description.mjs";
8
- import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-BXvelsZk.mjs";
9
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
8
+ import { d as telegramRuntimeSource, i as memberIdOf, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-Dzs8hUDB.mjs";
9
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
10
10
  import { formatAddress, parseAddress, scopedAddress } from "./sessions.mjs";
11
11
  import { telegramText } from "./texts.mjs";
12
12
  import { workspaceAction } from "./workspace-action.mjs";
@@ -9,7 +9,7 @@ import { n as contentText, t as CONTENT_CAPS } from "../../../_chunks/content-cD
9
9
  import { chatEvent, sessionFailureEventId } from "../chat-archive.mjs";
10
10
  import { currentConfirmationPrompt } from "../group-routing/messages.mjs";
11
11
  import { messageMetadata } from "./message-metadata.mjs";
12
- import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
12
+ import { n as currentInboundRequest, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
13
13
  import { reportMembership } from "./membership.mjs";
14
14
  import { currentDeliveryScope } from "./delivery-diagnostics.mjs";
15
15
  import { contentShape, messageContent } from "./content.mjs";
@@ -12,9 +12,9 @@ import { chatPostOperationId, isChatPost } from "../chat-post-confirmation.mjs";
12
12
  import { chatEvent } from "../chat-archive.mjs";
13
13
  import { chatPostCard, chatPostCardStatus, chatPostReceipt, withChatPostCard } from "./chat-post-card.mjs";
14
14
  import { answerMarker, isPendingQuestion, pendingQuestions, questionKey } from "../questions.mjs";
15
- import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
15
+ import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
16
16
  import { confirmationStatus, renderConfirmation, withConfirmationText } from "./confirmation-text.mjs";
17
- import { i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-BXvelsZk.mjs";
17
+ import { i as memberIdOf, o as telegramPrincipal } from "../../../_chunks/principal-Dzs8hUDB.mjs";
18
18
  import { formatAddress, scopedAddress } from "./sessions.mjs";
19
19
  import { createHash } from "node:crypto";
20
20
  import { telegramTextLinks } from "@segmentstream/ontology/telegram";
@@ -5,5 +5,5 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { isTechnicalText } from "../customer-text-safety.mjs";
8
- import { a as TelegramDeliveryError, c as customerCopy, d as failureText, f as formattingRefused, h as withDeliveryLocale, l as customerMessage, m as safeTelegramFetch, o as currentLocale, p as reportTelegramError, s as currentThreadId, u as customerText } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
8
+ import { a as TelegramDeliveryError, c as customerCopy, d as failureText, f as formattingRefused, h as withDeliveryLocale, l as customerMessage, m as safeTelegramFetch, o as currentLocale, p as reportTelegramError, s as currentThreadId, u as customerText } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
9
9
  export { TelegramDeliveryError, currentLocale, currentThreadId, customerCopy, customerMessage, customerText, failureText, formattingRefused, isTechnicalText, reportTelegramError, safeTelegramFetch, withDeliveryLocale };
@@ -5,8 +5,8 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { MAXIMUM_ATTACHMENT_BYTES, attachmentUrl } from "../attachments.mjs";
8
- import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
9
- import { n as chatLanguage } from "../../../_chunks/principal-BXvelsZk.mjs";
8
+ import { d as failureText, p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
9
+ import { n as chatLanguage } from "../../../_chunks/principal-Dzs8hUDB.mjs";
10
10
  import { describableImage, describeReceivedImage } from "./images.mjs";
11
11
  function telegramChat(chatId) {
12
12
  return `telegram:${chatId}`;
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { t as agentBuild } from "../../../_chunks/build-metadata-s0t4FPPK.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-5S6uTvyu.mjs";
8
8
  import { runtimeRequestFailure } from "./runtime-request.mjs";
9
9
  import { GET } from "eve/channels";
10
10
  const HEALTH_ROUTE = "/eve/v1/telegram/health";
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
8
8
  import { gateway, generateText } from "ai";
9
9
  const MAXIMUM_IMAGE_DESCRIPTION_BYTES = 5242880;
10
10
  const MAXIMUM_NATIVE_IMAGE_BYTES = 3145728;
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- export { t as InboundRequest, n as currentInboundRequest, r as runInboundRequest, i as withReplacedText } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
7
+ export { t as InboundRequest, n as currentInboundRequest, r as runInboundRequest, i as withReplacedText } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
@@ -6,7 +6,7 @@ __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { WorkspaceActionAlreadyDispatched } from "./workspace-action.mjs";
8
8
  import { structuredMessage } from "./structured.mjs";
9
- import { d as telegramRuntimeSource, n as chatLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-BXvelsZk.mjs";
9
+ import { d as telegramRuntimeSource, n as chatLanguage, o as telegramPrincipal, u as runtimeEnvelope } from "../../../_chunks/principal-Dzs8hUDB.mjs";
10
10
  import { routingBurst } from "../group-routing/burst.mjs";
11
11
  import { telegramSignals } from "./signals.mjs";
12
12
  import { addressingReason, chatKey, otherRecipient } from "../group-routing/signals.mjs";
@@ -30,7 +30,7 @@ import { MAXIMUM_ROUTING_ATTACHMENT_BYTES, describeRoutingAttachment, routingAtt
30
30
  import { recordGateDecision, recordInboundContent, recordRouteDecision } from "./chat-archive.mjs";
31
31
  import { contentShape, messageContent } from "./content.mjs";
32
32
  import { messageAudience } from "./audience.mjs";
33
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
33
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
34
34
  const MAXIMUM_QUOTE_LENGTH = 500;
35
35
  function buttonTo(text, url) {
36
36
  return { inline_keyboard: [[{
@@ -4,9 +4,9 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-BXvelsZk.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-s0t4FPPK.mjs";
9
- import { n as currentInboundRequest } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
7
+ import { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-Dzs8hUDB.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-5S6uTvyu.mjs";
9
+ import { n as currentInboundRequest } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
10
10
  import { object } from "../confirmation-description.mjs";
11
11
  import { needsConfirmation } from "../confirmations.mjs";
12
12
  import { OntologyActionNotPermitted, actionToolName, ontologyTools } from "../ontology-tools.mjs";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { DEFAULT_IMAGE_DESCRIPTION_MODEL } from "../../config.mjs";
8
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
8
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
9
9
  function planMedia(capabilities, descriptionModel = null) {
10
10
  if (typeof descriptionModel === "string") return {
11
11
  images: "describe",
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- export { t as TELEGRAM_AUTHENTICATOR, n as chatLanguage, r as identityProviderOf, i as memberIdOf, a as rolesOf, o as telegramPrincipal } from "../../../_chunks/principal-BXvelsZk.mjs";
7
+ export { t as TELEGRAM_AUTHENTICATOR, n as chatLanguage, r as identityProviderOf, i as memberIdOf, a as rolesOf, o as telegramPrincipal } from "../../../_chunks/principal-Dzs8hUDB.mjs";
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
7
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
8
8
  import { createHash } from "node:crypto";
9
9
  function strandedRun(error) {
10
10
  if (!(error instanceof Error) || error.name !== "RunKeyFetchError" || !("status" in error) || error.status !== 404) return;
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { confirmationLocale } from "./confirmation-text.mjs";
8
- import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
8
+ import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
9
9
  import { splitTelegramText } from "./format.mjs";
10
10
  import { inTelegramSendQueue } from "./send-queue.mjs";
11
11
  const NO_REPLY_TOOL = "no_reply";
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { d as telegramRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-BXvelsZk.mjs";
7
+ import { d as telegramRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-Dzs8hUDB.mjs";
8
8
  import { workspaceAction } from "./workspace-action.mjs";
9
9
  import { STRUCTURED_KINDS } from "./structured-settings.mjs";
10
10
  const record = (value) => {
@@ -7,8 +7,8 @@ __eveCreateRequire(import.meta.url);
7
7
  import { telegramText } from "./texts.mjs";
8
8
  import { confirmationLocale } from "./confirmation-text.mjs";
9
9
  import { recordSessionFailure } from "./chat-archive.mjs";
10
- import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
11
- import { i as memberIdOf } from "../../../_chunks/principal-BXvelsZk.mjs";
10
+ import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError, s as currentThreadId } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
11
+ import { i as memberIdOf } from "../../../_chunks/principal-Dzs8hUDB.mjs";
12
12
  import { modelServiceFailure } from "../model-service-failure.mjs";
13
13
  function telegramFailureEvents(input) {
14
14
  return {
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import "../connection-proxy.mjs";
8
- import { p as reportTelegramError } from "../../../_chunks/inbound-request-CK0QqEOP.mjs";
8
+ import { p as reportTelegramError } from "../../../_chunks/inbound-request-B3RhCuOw.mjs";
9
9
  import { gateway, transcribe } from "ai";
10
10
  const LABELS = {
11
11
  voice: "voice message",
@@ -0,0 +1,60 @@
1
+ import type { SessionAuthContext } from "eve/context";
2
+ import { type AuthFn } from "eve/channels/auth";
3
+ import { type Environment } from "../environment.js";
4
+ import { type RuntimeToken } from "../runtime-token.js";
5
+ /**
6
+ * A member who writes to the agent from a browser, such as the workspace app, shows an agent token:
7
+ * an ordinary access token of the ontology's OAuth server (`sso_…`), of the member's grant to the
8
+ * agent, which the app's browser gets at `POST /api/ontology/agent/tokens`. The agent asks the
9
+ * ontology whom it stands for; the session principal then acts for that member, naming the grant
10
+ * whenever it does, so the ontology admits it only while the grant stands and the member is active.
11
+ */
12
+ export declare const WEB_AUTHENTICATOR = "segmentstream-web";
13
+ /** The identity provider of a member who wrote on the web, as the ontology names it. */
14
+ export declare const WEB_PROVIDER = "web";
15
+ /** The header that carries the grant when the agent acts for a web member. */
16
+ export declare const AGENT_GRANT_HEADER = "X-SegmentStream-Agent-Grant";
17
+ /** The principal attribute holding the grant of the token the member showed. */
18
+ export declare const WEB_GRANT_ATTRIBUTE = "webGrant";
19
+ /** How every access token of the ontology's OAuth server, agent tokens too, begins. */
20
+ export declare const ACCESS_TOKEN_PREFIX = "sso_";
21
+ /** Where the agent asks the ontology whom an agent token stands for. */
22
+ export declare const INTROSPECTION_PATH = "/api/ontology/agent/tokens/introspect";
23
+ /** The member and chat an agent token stands for. */
24
+ export interface WebMember {
25
+ readonly memberId: string;
26
+ /** The OAuth grant the token is of: what the ontology admits the agent with. */
27
+ readonly grant: string;
28
+ /** The member's chat, `member:<id>` for their own. */
29
+ readonly chat: string;
30
+ readonly roles: ReadonlyArray<string>;
31
+ readonly name?: string;
32
+ }
33
+ /**
34
+ * Asks whom a token stands for, for the origin the member reached the agent on: the member, or
35
+ * `undefined` when it stands for nobody. Throws when the ontology cannot answer.
36
+ */
37
+ export type WebIntrospection = (token: string, origin: string) => Promise<WebMember | undefined>;
38
+ /** The member an introspection answer names, when it is active and names their own chat. */
39
+ export declare function webMemberOf(body: unknown): WebMember | undefined;
40
+ /** The ontology's introspection, called with the deployment's runtime token. */
41
+ export declare function ontologyIntrospection(options?: {
42
+ readonly environment?: Environment;
43
+ readonly token?: RuntimeToken;
44
+ readonly fetch?: typeof fetch;
45
+ }): WebIntrospection;
46
+ /** The session principal of a member who wrote on the web, in their own chat. */
47
+ export declare function webPrincipal(member: WebMember): SessionAuthContext;
48
+ /** The grant a web principal carries; `undefined` for any other principal. */
49
+ export declare function webGrantOf(principal: SessionAuthContext | null | undefined): string | undefined;
50
+ export interface WebAuthOptions {
51
+ /** Whom a token stands for; by default the ontology's answer. */
52
+ readonly introspect?: WebIntrospection;
53
+ }
54
+ /**
55
+ * The route authenticator for the agent's own HTTP channel: a request with an agent token runs as
56
+ * the member it stands for, and any other request goes on to the next authenticator. An answer to
57
+ * one of the agent's confirmations through its own buttons is stamped with its decision, as a click
58
+ * on a Telegram card is, so that only a click, never a typed message, decides a confirmation.
59
+ */
60
+ export declare function webAuth(options?: WebAuthOptions): AuthFn<Request>;