@segmentstream/agent 0.92.0 → 0.93.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 +6 -0
- package/dist/_chunks/{build-metadata-C_9WeVSz.mjs → build-metadata-CP0iLqzp.mjs} +1 -1
- package/dist/extension/config.d.ts +9 -0
- package/dist/extension/config.mjs +25 -0
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-persona.d.ts +2 -0
- package/dist/extension/lib/chat-persona.mjs +5 -5
- package/dist/extension/lib/chats.d.ts +2 -0
- package/dist/extension/lib/chats.mjs +4 -2
- package/dist/extension/lib/public-group.d.ts +19 -0
- package/dist/extension/lib/public-group.mjs +77 -0
- package/dist/extension/lib/slack/adapter.d.ts +1 -0
- package/dist/extension/lib/slack/adapter.mjs +20 -4
- package/dist/extension/lib/telegram/adapter.mjs +5 -3
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +17 -0
- package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
- package/dist/extension/lib/telegram/membership.mjs +8 -2
- package/dist/extension/lib/web-search.d.ts +2 -0
- package/dist/extension/lib/web-search.mjs +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.93.0
|
|
4
|
+
|
|
5
|
+
Allow workspace operators to enable bounded, tool-free answers to unlinked senders in individual Telegram and Slack group chats. Dedicated connections can use a verified inviter's existing permission to open a newly joined group.
|
|
6
|
+
|
|
7
|
+
Pins @segmentstream/ontology 0.175.0.
|
|
8
|
+
|
|
3
9
|
## 0.92.0
|
|
4
10
|
|
|
5
11
|
Telegram messages, edits and delivery receipts keep the bot account that received or sent them.
|
|
@@ -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
|
-
var version = "0.
|
|
7
|
+
var version = "0.93.0";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -74,7 +74,15 @@ export interface FirstContactSettings {
|
|
|
74
74
|
}
|
|
75
75
|
export declare const ADMISSION_REPLY_KEYS: readonly ["pairingRequired", "pairingButton", "groupPairingButton", "limited", "perSenderLimited", "workspaceLimited", "registrationsLimited", "groupPairingRequired", "refused"];
|
|
76
76
|
export type AdmissionReplies = Partial<Record<(typeof ADMISSION_REPLY_KEYS)[number], LocalizedText>>;
|
|
77
|
+
export interface PublicGroupSettings {
|
|
78
|
+
readonly model: string;
|
|
79
|
+
/** Workspace-published material for an isolated, text-only answer. */
|
|
80
|
+
readonly instructions: string;
|
|
81
|
+
/** Dedicated group connections which may be opened by an authorized inviter. */
|
|
82
|
+
readonly trustedJoinChannels?: readonly string[];
|
|
83
|
+
}
|
|
77
84
|
export interface AdmissionSettings {
|
|
85
|
+
readonly publicGroups?: PublicGroupSettings;
|
|
78
86
|
readonly personas?: PersonaSettings;
|
|
79
87
|
readonly firstContact: FirstContactSettings | null;
|
|
80
88
|
readonly limits: AdmissionLimits;
|
|
@@ -87,6 +95,7 @@ export interface AdmissionSettings {
|
|
|
87
95
|
* the values validation allows.
|
|
88
96
|
*/
|
|
89
97
|
export interface SegmentStreamAgentConfigInput {
|
|
98
|
+
readonly publicGroups?: PublicGroupSettings;
|
|
90
99
|
readonly groups?: GroupPolicyInput;
|
|
91
100
|
readonly texts?: TelegramTexts;
|
|
92
101
|
readonly firstContact?: FirstContactSettings;
|
|
@@ -1114,6 +1114,7 @@ function validateConfig(input, options = {}) {
|
|
|
1114
1114
|
"sessions",
|
|
1115
1115
|
"confirmations",
|
|
1116
1116
|
"firstContact",
|
|
1117
|
+
"publicGroups",
|
|
1117
1118
|
"limits",
|
|
1118
1119
|
"replies",
|
|
1119
1120
|
"texts",
|
|
@@ -1259,6 +1260,29 @@ function validateConfig(input, options = {}) {
|
|
|
1259
1260
|
const sessions = sessionSettings(root?.sessions, issues);
|
|
1260
1261
|
const firstContact = firstContactSettings(root?.firstContact, issues, !legacyArchive);
|
|
1261
1262
|
const limits = admissionLimits(root?.limits, issues);
|
|
1263
|
+
const publicGroupInput = section({
|
|
1264
|
+
value: root?.publicGroups,
|
|
1265
|
+
path: ["publicGroups"],
|
|
1266
|
+
allowed: [
|
|
1267
|
+
"model",
|
|
1268
|
+
"instructions",
|
|
1269
|
+
"trustedJoinChannels"
|
|
1270
|
+
],
|
|
1271
|
+
issues
|
|
1272
|
+
});
|
|
1273
|
+
let publicGroups;
|
|
1274
|
+
if (publicGroupInput) {
|
|
1275
|
+
const { model, instructions, trustedJoinChannels } = publicGroupInput;
|
|
1276
|
+
if (typeof model !== "string" || !model.trim() || model.length > 256 || typeof instructions !== "string" || !instructions.trim() || instructions.length > 32e3 || trustedJoinChannels !== void 0 && (!Array.isArray(trustedJoinChannels) || !trustedJoinChannels.every((channel) => typeof channel === "string" && Object.hasOwn(channels ?? {}, channel)))) issues.push({
|
|
1277
|
+
path: ["publicGroups"],
|
|
1278
|
+
message: "Supply a model, public instructions and optional configured channel names."
|
|
1279
|
+
});
|
|
1280
|
+
else publicGroups = {
|
|
1281
|
+
model,
|
|
1282
|
+
instructions,
|
|
1283
|
+
...trustedJoinChannels ? { trustedJoinChannels } : {}
|
|
1284
|
+
};
|
|
1285
|
+
}
|
|
1262
1286
|
const replies = admissionReplies(root?.replies, issues, !legacyArchive);
|
|
1263
1287
|
const texts = telegramTexts(root?.texts, issues);
|
|
1264
1288
|
if (!legacyArchive && replies.groupPairingButton !== void 0 && replies.groupPairingRequired === void 0) issues.push({
|
|
@@ -1374,6 +1398,7 @@ function validateConfig(input, options = {}) {
|
|
|
1374
1398
|
...browser === null ? {} : { browser },
|
|
1375
1399
|
sessions,
|
|
1376
1400
|
firstContact,
|
|
1401
|
+
...publicGroups ? { publicGroups } : {},
|
|
1377
1402
|
limits,
|
|
1378
1403
|
replies,
|
|
1379
1404
|
texts,
|
|
@@ -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 agentBuild } from "../../_chunks/build-metadata-
|
|
7
|
+
export { t as agentBuild } from "../../_chunks/build-metadata-CP0iLqzp.mjs";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { SessionAuthContext } from "eve/context";
|
|
2
2
|
import { chatPersona, type PersonaSettings } from "../personas.js";
|
|
3
|
+
/** A production runtime lookup on the current chat. An outage must not silently change its persona. */
|
|
4
|
+
export declare function chatRuntimeRequest(operation: string, data: Record<string, unknown>): Promise<any>;
|
|
3
5
|
export declare function resolveChatPersona(settings: PersonaSettings, principal: SessionAuthContext | null | undefined, read?: (key: string) => Promise<string | null>): Promise<{
|
|
4
6
|
readonly name: string;
|
|
5
7
|
readonly source: "chat";
|
|
@@ -9,7 +9,7 @@ import { Ft as chatAddressOf, It as chatChannel, i as memberIdOf, ot as guestIdO
|
|
|
9
9
|
import { appOrigin, ontologyDeploymentHeaders } from "./environment.mjs";
|
|
10
10
|
import { localizedText } from "./admission.mjs";
|
|
11
11
|
import { runtimeToken } from "./runtime-token.mjs";
|
|
12
|
-
async function
|
|
12
|
+
async function chatRuntimeRequest(operation, data) {
|
|
13
13
|
const response = await fetch(`${appOrigin()}/api/ontology/agent/chats/${operation}`, {
|
|
14
14
|
method: "POST",
|
|
15
15
|
redirect: "error",
|
|
@@ -21,11 +21,11 @@ async function request(operation, data) {
|
|
|
21
21
|
body: JSON.stringify(data),
|
|
22
22
|
signal: AbortSignal.timeout(5e3)
|
|
23
23
|
});
|
|
24
|
-
if (!response.ok) throw new Error(`
|
|
24
|
+
if (!response.ok) throw new Error(`The chat runtime request failed (HTTP ${response.status}).`);
|
|
25
25
|
return response.json();
|
|
26
26
|
}
|
|
27
27
|
async function readAssignment(key) {
|
|
28
|
-
const body = await
|
|
28
|
+
const body = await chatRuntimeRequest("persona", { key });
|
|
29
29
|
if (body?.persona !== null && typeof body?.persona !== "string") throw new Error("Invalid chat persona response.");
|
|
30
30
|
return body.persona;
|
|
31
31
|
}
|
|
@@ -47,7 +47,7 @@ async function offerPersona(settings, selection, principal, deliver, locale) {
|
|
|
47
47
|
const memberId = memberIdOf(principal);
|
|
48
48
|
if (!text || !chat || !memberId || selection?.source !== "default" || !selection.name) return;
|
|
49
49
|
try {
|
|
50
|
-
const receipt = await
|
|
50
|
+
const receipt = await chatRuntimeRequest("persona-notice", {
|
|
51
51
|
key: `${chatChannel(chat)}:${chat.chatId}`,
|
|
52
52
|
memberId,
|
|
53
53
|
provider: chat.provider
|
|
@@ -72,4 +72,4 @@ async function personaPrincipal(settings, principal, deliver) {
|
|
|
72
72
|
}
|
|
73
73
|
} : principal;
|
|
74
74
|
}
|
|
75
|
-
export { offerPersona, personaPrincipal, resolveChatPersona };
|
|
75
|
+
export { chatRuntimeRequest, offerPersona, personaPrincipal, resolveChatPersona };
|
|
@@ -12,6 +12,7 @@ export interface ChatReport {
|
|
|
12
12
|
readonly chatId: string;
|
|
13
13
|
readonly title: ChatTitle;
|
|
14
14
|
readonly memberId?: string;
|
|
15
|
+
readonly inviter?: string;
|
|
15
16
|
}
|
|
16
17
|
export interface AgentChats {
|
|
17
18
|
/**
|
|
@@ -68,6 +69,7 @@ export declare function agentChats(input: {
|
|
|
68
69
|
/** The provider whose chats these are, as the registry records them. */
|
|
69
70
|
readonly provider: string;
|
|
70
71
|
readonly identities: () => AgentIdentities;
|
|
72
|
+
readonly onInvite?: (chatId: string, inviter: string) => Promise<void>;
|
|
71
73
|
readonly now?: () => number;
|
|
72
74
|
readonly log?: (message: string, error: unknown) => void;
|
|
73
75
|
readonly logError?: (message: string, error: unknown) => void;
|
|
@@ -93,7 +93,7 @@ function agentChats(input) {
|
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
95
|
return {
|
|
96
|
-
async joined({ chatId, title }) {
|
|
96
|
+
async joined({ chatId, title, inviter }) {
|
|
97
97
|
const known = chats.get(chatId);
|
|
98
98
|
const remembered = {
|
|
99
99
|
reportedAt: now(),
|
|
@@ -101,7 +101,9 @@ function agentChats(input) {
|
|
|
101
101
|
chat: known?.chat
|
|
102
102
|
};
|
|
103
103
|
remember(chatId, remembered);
|
|
104
|
-
|
|
104
|
+
const outcome = await report(chatId, remembered, { title });
|
|
105
|
+
if (outcome === "failed") restore(chatId, remembered, known);
|
|
106
|
+
else if (outcome === "reported" && inviter) await input.onInvite?.(chatId, inviter);
|
|
105
107
|
},
|
|
106
108
|
health() {
|
|
107
109
|
const failedChats = [...failures.values()];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AdmissionSettings } from "../config.js";
|
|
2
|
+
/** Everyone in an opened group sees the reply, including when an employee asks. */
|
|
3
|
+
export declare function isPublicGroup(admission: AdmissionSettings, channel: string, chat: string, sender: string): Promise<boolean>;
|
|
4
|
+
/** An unlinked sender can only submit this message to the workspace's public instructions.
|
|
5
|
+
* No member principal, history, tools, workspace files or channel tokens enter the model call. */
|
|
6
|
+
export declare function answerPublicGroup(input: {
|
|
7
|
+
admission: AdmissionSettings;
|
|
8
|
+
channel: string;
|
|
9
|
+
chat: string;
|
|
10
|
+
sender: string;
|
|
11
|
+
message: string;
|
|
12
|
+
text: string;
|
|
13
|
+
locale?: string;
|
|
14
|
+
post: (text: string) => Promise<unknown>;
|
|
15
|
+
claim?: () => Promise<boolean>;
|
|
16
|
+
finish?: (delivered: boolean) => Promise<void>;
|
|
17
|
+
}): Promise<boolean>;
|
|
18
|
+
/** An authenticated provider join only offers the inviter's own, row-scoped authority. */
|
|
19
|
+
export declare function publicGroupInvite(admission: AdmissionSettings, provider: "slack" | "telegram", channel: string, chat: string, inviter: string): Promise<void>;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { fileURLToPath as __eveFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __eveDirname } from "node:path";
|
|
3
|
+
import { createRequire as __eveCreateRequire } from "node:module";
|
|
4
|
+
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
|
+
__eveDirname(__filename);
|
|
6
|
+
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import { localizedText } from "./admission.mjs";
|
|
8
|
+
import { chatRuntimeRequest } from "./chat-persona.mjs";
|
|
9
|
+
import { ontologyGuestUsage } from "./guest-usage.mjs";
|
|
10
|
+
import { gatewayCostOf } from "./web-search.mjs";
|
|
11
|
+
import { gateway, generateText } from "ai";
|
|
12
|
+
async function isPublicGroup(admission, channel, chat, sender) {
|
|
13
|
+
if (!admission.publicGroups) return false;
|
|
14
|
+
const result = await chatRuntimeRequest("public-turn", {
|
|
15
|
+
channel,
|
|
16
|
+
chat,
|
|
17
|
+
sender,
|
|
18
|
+
check: true
|
|
19
|
+
});
|
|
20
|
+
if (result?.status !== "public" && result?.status !== "closed") throw new Error("Invalid group access.");
|
|
21
|
+
return result.status === "public";
|
|
22
|
+
}
|
|
23
|
+
async function answerPublicGroup(input) {
|
|
24
|
+
const settings = input.admission.publicGroups;
|
|
25
|
+
if (!settings || !input.text.trim()) return false;
|
|
26
|
+
if (input.claim && !await input.claim()) return true;
|
|
27
|
+
let delivered = false;
|
|
28
|
+
try {
|
|
29
|
+
const turn = await chatRuntimeRequest("public-turn", {
|
|
30
|
+
channel: input.channel,
|
|
31
|
+
chat: input.chat,
|
|
32
|
+
sender: input.sender,
|
|
33
|
+
limits: input.admission.limits
|
|
34
|
+
});
|
|
35
|
+
if (turn?.status === "closed") return false;
|
|
36
|
+
if (turn?.status === "limited") {
|
|
37
|
+
const text = localizedText(input.admission.replies.limited, input.locale);
|
|
38
|
+
if (text) await input.post(text);
|
|
39
|
+
delivered = true;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (turn?.status !== "admitted" || typeof turn.guestId !== "string") throw new Error("Invalid public group admission.");
|
|
43
|
+
const reply = await generateText({
|
|
44
|
+
model: gateway(settings.model),
|
|
45
|
+
system: settings.instructions,
|
|
46
|
+
prompt: input.text.slice(0, 8e3),
|
|
47
|
+
maxRetries: 0,
|
|
48
|
+
maxOutputTokens: 600,
|
|
49
|
+
abortSignal: AbortSignal.timeout(3e4)
|
|
50
|
+
});
|
|
51
|
+
const costUsd = gatewayCostOf(reply.providerMetadata);
|
|
52
|
+
if (costUsd > 0) await ontologyGuestUsage()({
|
|
53
|
+
guestId: turn.guestId,
|
|
54
|
+
costUsd,
|
|
55
|
+
key: JSON.stringify([
|
|
56
|
+
input.channel,
|
|
57
|
+
input.chat,
|
|
58
|
+
input.message
|
|
59
|
+
]).slice(0, 256)
|
|
60
|
+
});
|
|
61
|
+
const text = reply.text.trim();
|
|
62
|
+
if (!text) throw new Error("The public group answer was empty.");
|
|
63
|
+
await input.post(text.slice(0, 3500));
|
|
64
|
+
delivered = true;
|
|
65
|
+
return true;
|
|
66
|
+
} finally {
|
|
67
|
+
await input.finish?.(delivered);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function publicGroupInvite(admission, provider, channel, chat, inviter) {
|
|
71
|
+
if (admission.publicGroups?.trustedJoinChannels?.includes(channel)) await chatRuntimeRequest("public-invite", {
|
|
72
|
+
key: `${channel}:${chat}`,
|
|
73
|
+
provider,
|
|
74
|
+
inviter
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export { answerPublicGroup, isPublicGroup, publicGroupInvite };
|
|
@@ -171,6 +171,7 @@ export declare function receive(input: {
|
|
|
171
171
|
readonly ctx: Pick<SlackInboundMessageContext, "thread" | "edit" | "slack"> & Partial<Pick<SlackInboundMessageContext, "resolveSession" | "isSubscribed">>;
|
|
172
172
|
readonly message: Pick<SlackMessage, "author" | "text" | "attachments" | "ts"> & Partial<Pick<SlackMessage, "raw">>;
|
|
173
173
|
readonly direct: boolean;
|
|
174
|
+
readonly mention?: boolean;
|
|
174
175
|
readonly admission: AdmissionSettings;
|
|
175
176
|
readonly identities: AgentIdentities;
|
|
176
177
|
readonly environment: Environment;
|
|
@@ -4,6 +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 { answerPublicGroup, isPublicGroup, publicGroupInvite } from "../public-group.mjs";
|
|
7
8
|
import { admitMessage, localizedText } from "../admission.mjs";
|
|
8
9
|
import { agentToolsAttribute } from "../agent-tools.mjs";
|
|
9
10
|
import { agentChats, channelChats } from "../chats.mjs";
|
|
@@ -77,7 +78,8 @@ async function reportMembership(input) {
|
|
|
77
78
|
if (typeof bot === "string" && user === bot) {
|
|
78
79
|
if (joined) await input.chats.joined({
|
|
79
80
|
chatId,
|
|
80
|
-
title
|
|
81
|
+
title,
|
|
82
|
+
...typeof event.inviter === "string" && event.inviter !== bot && event.inviter ? { inviter: event.inviter } : {}
|
|
81
83
|
});
|
|
82
84
|
else await input.chats.agentLeft({
|
|
83
85
|
chatId,
|
|
@@ -229,7 +231,8 @@ function segmentstreamSlack(options) {
|
|
|
229
231
|
});
|
|
230
232
|
const registry = options.chats ?? channelChats("slack", (provider) => agentChats({
|
|
231
233
|
provider,
|
|
232
|
-
identities: pairing
|
|
234
|
+
identities: pairing,
|
|
235
|
+
onInvite: (chat, inviter) => publicGroupInvite(options.admission(), "slack", provider, chat, inviter)
|
|
233
236
|
}));
|
|
234
237
|
const chats = () => registry;
|
|
235
238
|
let records = options.archive;
|
|
@@ -275,12 +278,13 @@ function segmentstreamSlack(options) {
|
|
|
275
278
|
report: reportWithReference
|
|
276
279
|
}) }
|
|
277
280
|
};
|
|
278
|
-
const admit = (direct) => (ctx, message) => {
|
|
281
|
+
const admit = (direct, mention = false) => (ctx, message) => {
|
|
279
282
|
const work = requestWork.getStore();
|
|
280
283
|
return receive({
|
|
281
284
|
ctx,
|
|
282
285
|
message,
|
|
283
286
|
direct,
|
|
287
|
+
mention,
|
|
284
288
|
admission: options.admission(),
|
|
285
289
|
identities: pairing(),
|
|
286
290
|
environment,
|
|
@@ -350,7 +354,7 @@ function segmentstreamSlack(options) {
|
|
|
350
354
|
fetch: slackFetch
|
|
351
355
|
},
|
|
352
356
|
renderers: [slackConfirmationRenderer(options.texts ?? (() => ({})))],
|
|
353
|
-
onAppMention: admit(false),
|
|
357
|
+
onAppMention: admit(false, true),
|
|
354
358
|
onDirectMessage: admit(true),
|
|
355
359
|
onMessage: async (ctx, message) => {
|
|
356
360
|
if (!await followsThreadReply({
|
|
@@ -476,6 +480,18 @@ async function receive(input) {
|
|
|
476
480
|
} } : {},
|
|
477
481
|
inboxFailed: (error) => report("inbox_report_failed", error)
|
|
478
482
|
});
|
|
483
|
+
if (!input.direct && (resolution.status === "pairing_required" || resolution.status === "existing" || resolution.status === "created") && await isPublicGroup(admission, currentChannel("slack"), ctx.slack.channelId, user)) {
|
|
484
|
+
if (input.mention && ctx.edit === void 0) await answerPublicGroup({
|
|
485
|
+
admission,
|
|
486
|
+
channel: currentChannel("slack"),
|
|
487
|
+
chat: ctx.slack.channelId,
|
|
488
|
+
sender: user,
|
|
489
|
+
message: message.ts,
|
|
490
|
+
text: message.text,
|
|
491
|
+
post: (text) => ctx.thread.post(text)
|
|
492
|
+
});
|
|
493
|
+
return null;
|
|
494
|
+
}
|
|
479
495
|
switch (resolution.status) {
|
|
480
496
|
case "existing":
|
|
481
497
|
case "created":
|
|
@@ -4,6 +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 { publicGroupInvite } from "../public-group.mjs";
|
|
7
8
|
import { logConfirmationPress } from "./confirmation-press.mjs";
|
|
8
9
|
import { object } from "../confirmation-description.mjs";
|
|
9
10
|
import { archivedRoutingMessages } from "../group-routing/routing-context.mjs";
|
|
@@ -11,7 +12,7 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
|
|
|
11
12
|
import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
|
|
12
13
|
import { handleWorkspaceCallback } from "./callbacks.mjs";
|
|
13
14
|
import { telegramText, withTelegramTexts } from "./texts.mjs";
|
|
14
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
15
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-CP0iLqzp.mjs";
|
|
15
16
|
import { attachmentLifecycle } from "./lifecycle.mjs";
|
|
16
17
|
import { manifestOf } from "../../config.mjs";
|
|
17
18
|
import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
|
|
@@ -25,8 +26,8 @@ import { a as captureTelegramFetch, h as telegramChatCapture, i as captureRouteD
|
|
|
25
26
|
import { runtimeTokenVerifier } from "../runtime-identity.mjs";
|
|
26
27
|
import { runtimeToken } from "../runtime-token.mjs";
|
|
27
28
|
import { botIdentityCache, proxiedBotRequest, runtimeBotIdentity } from "./bot.mjs";
|
|
28
|
-
import { handleConfirmationCallback, telegramConfirmationEvents } from "./confirmations.mjs";
|
|
29
29
|
import { isWorkspaceCallback } from "../workspace-action.mjs";
|
|
30
|
+
import { handleConfirmationCallback, telegramConfirmationEvents } from "./confirmations.mjs";
|
|
30
31
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
31
32
|
import { telegramAppLinkContext } from "./app-links.mjs";
|
|
32
33
|
import { gatewayImageDescriber } from "../inbound-media/images.mjs";
|
|
@@ -158,7 +159,8 @@ function segmentstreamTelegram(options) {
|
|
|
158
159
|
}
|
|
159
160
|
const chats = channelChats("telegram", (provider) => agentChats({
|
|
160
161
|
provider,
|
|
161
|
-
identities: pairing
|
|
162
|
+
identities: pairing,
|
|
163
|
+
onInvite: (chat, inviter) => publicGroupInvite(options.admission?.() ?? manifestOf({}), "telegram", provider, chat, inviter)
|
|
162
164
|
}));
|
|
163
165
|
const capture = telegramChatCapture({
|
|
164
166
|
archive,
|
|
@@ -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-
|
|
7
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-CP0iLqzp.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";
|
|
@@ -6,6 +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 { answerPublicGroup, isPublicGroup } from "../public-group.mjs";
|
|
9
10
|
import { currentChannel } from "../channel-scope.mjs";
|
|
10
11
|
import { Ot as runtimeEnvelope, f as attachmentsContext, kt as telegramRuntimeSource, n as chatLanguage, o as telegramPrincipal, x as attachmentUrl, xt as reportTelegramError } from "../../../_chunks/principal-DL9NdRRP.mjs";
|
|
11
12
|
import { routingBurst } from "../group-routing/burst.mjs";
|
|
@@ -406,6 +407,22 @@ async function handleInboundMessage(input) {
|
|
|
406
407
|
author: authorOf(sent.from, void 0)
|
|
407
408
|
});
|
|
408
409
|
}
|
|
410
|
+
if (group && (lookup.status === "pairing_required" || lookup.status === "existing" || lookup.status === "created") && await isPublicGroup(dependencies.admission(), currentChannel("telegram"), String(sent.chat.id), String(sent.from.id))) {
|
|
411
|
+
if (turn && !input.request?.edited) await answerPublicGroup({
|
|
412
|
+
admission: dependencies.admission(),
|
|
413
|
+
channel: currentChannel("telegram"),
|
|
414
|
+
chat: String(sent.chat.id),
|
|
415
|
+
sender: String(sent.from.id),
|
|
416
|
+
message: String(sent.messageId),
|
|
417
|
+
text: sent.text,
|
|
418
|
+
locale: sent.from.languageCode,
|
|
419
|
+
post: (value) => context.telegram.post(value),
|
|
420
|
+
...input.request?.claimTurn && { claim: input.request.claimTurn },
|
|
421
|
+
...input.request?.finishClaim && { finish: input.request.finishClaim }
|
|
422
|
+
});
|
|
423
|
+
await observeRaw();
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
409
426
|
if (lookup.status !== "existing" && lookup.status !== "created") {
|
|
410
427
|
const configuredGroupPairing = lookup.status === "pairing_required" && localizedText(dependencies.admission().replies.groupPairingRequired, sent.from.languageCode) !== void 0;
|
|
411
428
|
await reject(lookup, addressed !== void 0 && (!group || lookup.status === "limited" || configuredGroupPairing));
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { E as OntologyActionNotPermitted, Et as principalRuntimeSource, L as needsConfirmation, Ot as runtimeEnvelope, W as member, c as currentInboundRequest, j as ontologyTools, k as actionToolName, kt as telegramRuntimeSource } from "../../../_chunks/principal-DL9NdRRP.mjs";
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
8
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-CP0iLqzp.mjs";
|
|
9
9
|
import { object } from "../confirmation-description.mjs";
|
|
10
10
|
var AttachmentLifecycleNotPermitted = class extends Error {
|
|
11
11
|
code = "attachment_lifecycle_not_permitted";
|
|
@@ -22,8 +22,14 @@ async function reportMembership(input) {
|
|
|
22
22
|
title: typeof chat.title === "string" ? chat.title : ""
|
|
23
23
|
};
|
|
24
24
|
if (mine) {
|
|
25
|
-
if (isMember(next))
|
|
26
|
-
|
|
25
|
+
if (isMember(next)) {
|
|
26
|
+
const actor = record(update.from);
|
|
27
|
+
const newlyJoined = previous.status === "left" || previous.status === "kicked" || previous.status === "restricted" && previous.is_member === false;
|
|
28
|
+
await input.chats.joined({
|
|
29
|
+
...report,
|
|
30
|
+
...newlyJoined && actor.is_bot === false && typeof actor.id === "number" && Number.isSafeInteger(actor.id) && actor.id > 0 ? { inviter: String(actor.id) } : {}
|
|
31
|
+
});
|
|
32
|
+
} else if (isMember(previous) && (next.status === "left" || next.status === "kicked" || next.status === "restricted")) await input.chats.agentLeft(report);
|
|
27
33
|
return;
|
|
28
34
|
}
|
|
29
35
|
const user = record(next.user);
|
|
@@ -51,6 +51,8 @@ export interface SearchAnswer {
|
|
|
51
51
|
}
|
|
52
52
|
/** Runs one search. Tests pass their own. */
|
|
53
53
|
export type Searcher = (input: WebSearchInput, signal?: AbortSignal) => Promise<SearchAnswer>;
|
|
54
|
+
/** The cost AI Gateway reports in a model answer's metadata, as eve reads it. */
|
|
55
|
+
export declare function gatewayCostOf(metadata: unknown): number;
|
|
54
56
|
/** The search through AI Gateway, with the deployment's own Gateway identity. */
|
|
55
57
|
export declare const gatewaySearcher: Searcher;
|
|
56
58
|
/** The pages of the provider's output, or why there are none. */
|
|
@@ -85,4 +85,4 @@ async function searchWeb(input, options = {}) {
|
|
|
85
85
|
if (answer.output === void 0) throw new WebSearchFailedError("The search did not run; try again.");
|
|
86
86
|
return searchResultOf(answer.output);
|
|
87
87
|
}
|
|
88
|
-
export { MAXIMUM_EXCERPT_CHARACTERS, MAXIMUM_OBJECTIVE_CHARACTERS, MAXIMUM_QUERIES, MAXIMUM_QUERY_CHARACTERS, MAXIMUM_RESULTS, WEB_SEARCH_MODEL, WebSearchFailedError, gatewaySearcher, searchResultOf, searchWeb };
|
|
88
|
+
export { MAXIMUM_EXCERPT_CHARACTERS, MAXIMUM_OBJECTIVE_CHARACTERS, MAXIMUM_QUERIES, MAXIMUM_QUERY_CHARACTERS, MAXIMUM_RESULTS, WEB_SEARCH_MODEL, WebSearchFailedError, gatewayCostOf, gatewaySearcher, searchResultOf, searchWeb };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.93.0",
|
|
4
4
|
"description": "The SegmentStream workspace agent: the ontology as tools, acting as the member who writes, and the browser, Telegram, WhatsApp and Slack through the workspace's connections.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"@chat-adapter/state-memory": "4.42.0",
|
|
89
89
|
"@chat-adapter/telegram": "4.41.0",
|
|
90
90
|
"@chat-adapter/whatsapp": "4.42.0",
|
|
91
|
-
"@segmentstream/ontology": "0.
|
|
91
|
+
"@segmentstream/ontology": "0.175.0",
|
|
92
92
|
"@vercel/oidc": "^3.8.4",
|
|
93
93
|
"ai": "^7.0.172",
|
|
94
94
|
"chat": "4.42.0",
|