@segmentstream/agent 0.12.2 → 0.14.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 +29 -22
- package/dist/_chunks/{build-metadata-CLprTpsn.mjs → build-metadata-BB2uSGsI.mjs} +1 -1
- package/dist/_chunks/{inbound-request-BrWspFw5.mjs → inbound-request-BXhiIph-.mjs} +21 -19
- package/dist/_chunks/principal-VFQWqe5S.mjs +126 -0
- package/dist/extension/_manifest.json +0 -1
- package/dist/extension/config.d.ts +23 -5
- package/dist/extension/config.mjs +167 -18
- package/dist/extension/extension.d.ts +7 -1
- package/dist/extension/hooks/authorization.d.ts +3 -0
- package/dist/extension/hooks/authorization.mjs +16 -0
- package/dist/extension/instructions.md +3 -4
- package/dist/extension/lib/attachment-tools.mjs +1 -1
- package/dist/extension/lib/attachments.d.ts +2 -0
- package/dist/extension/lib/attachments.mjs +1 -0
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-post-confirmation.d.ts +1 -0
- package/dist/extension/lib/chat-post-confirmation.mjs +4 -2
- package/dist/extension/lib/confirmation-outcome.d.ts +1 -1
- package/dist/extension/lib/confirmations.d.ts +2 -0
- package/dist/extension/lib/confirmations.mjs +8 -5
- package/dist/extension/lib/conversation-runtime.mjs +1 -1
- package/dist/extension/lib/deferred-confirmations.d.ts +5 -0
- package/dist/extension/lib/deferred-confirmations.mjs +23 -10
- package/dist/extension/lib/ontology-connection.d.ts +1 -0
- package/dist/extension/lib/ontology-connection.mjs +18 -12
- package/dist/extension/lib/ontology-gateway.mjs +9 -2
- package/dist/extension/lib/ontology-metadata-read.mjs +1 -1
- package/dist/extension/lib/ontology-tools.d.ts +9 -2
- package/dist/extension/lib/ontology-tools.mjs +29 -5
- package/dist/extension/lib/runtime-envelope.d.ts +28 -0
- package/dist/extension/lib/runtime-envelope.mjs +8 -0
- package/dist/extension/lib/stored-files.mjs +1 -1
- package/dist/extension/lib/telegram/adapter.mjs +53 -11
- package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
- package/dist/extension/lib/telegram/attachments-send.mjs +15 -12
- package/dist/extension/lib/telegram/callbacks.d.ts +18 -0
- package/dist/extension/lib/telegram/callbacks.mjs +155 -0
- package/dist/extension/lib/telegram/chat-post-card.d.ts +1 -1
- package/dist/extension/lib/telegram/chat-post-card.mjs +13 -10
- package/dist/extension/lib/telegram/confirmation-expiry.d.ts +2 -1
- package/dist/extension/lib/telegram/confirmation-expiry.mjs +6 -5
- package/dist/extension/lib/telegram/confirmation-text.d.ts +1 -1
- package/dist/extension/lib/telegram/confirmation-text.mjs +18 -12
- package/dist/extension/lib/telegram/confirmations.mjs +28 -23
- package/dist/extension/lib/telegram/conversations.d.ts +2 -0
- package/dist/extension/lib/telegram/conversations.mjs +14 -1
- package/dist/extension/lib/telegram/customer-text.d.ts +9 -8
- package/dist/extension/lib/telegram/customer-text.mjs +1 -1
- package/dist/extension/lib/telegram/deferred-confirmations.mjs +14 -13
- package/dist/extension/lib/telegram/files.mjs +2 -2
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/images.mjs +1 -1
- package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +25 -20
- package/dist/extension/lib/telegram/lifecycle.mjs +15 -3
- package/dist/extension/lib/telegram/media-policy.mjs +1 -1
- package/dist/extension/lib/telegram/principal.d.ts +1 -0
- package/dist/extension/lib/telegram/principal.mjs +1 -49
- package/dist/extension/lib/telegram/sessions.d.ts +3 -1
- package/dist/extension/lib/telegram/silent.mjs +3 -3
- package/dist/extension/lib/telegram/texts.d.ts +16 -0
- package/dist/extension/lib/telegram/texts.mjs +70 -0
- package/dist/extension/lib/telegram/turn-errors.d.ts +1 -1
- package/dist/extension/lib/telegram/turn-errors.mjs +38 -4
- package/dist/extension/lib/telegram/voice.mjs +1 -1
- package/dist/extension/lib/telegram/workspace-action.d.ts +21 -0
- package/dist/extension/lib/telegram/workspace-action.mjs +23 -0
- package/dist/extension/model.mjs +1 -1
- package/dist/extension/schedules/confirmations.mjs +1 -1
- package/dist/extension/tools/attachments_promote.mjs +8 -0
- package/dist/extension/tools/ontology.mjs +2 -2
- package/dist/extension/tools/questions_ask.mjs +1 -1
- package/package.json +2 -2
- package/dist/extension/connections/ontology.d.ts +0 -7
- package/dist/extension/connections/ontology.mjs +0 -11
|
@@ -4,16 +4,21 @@ 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 {
|
|
7
|
+
import { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-VFQWqe5S.mjs";
|
|
8
8
|
import { object } from "../confirmation-description.mjs";
|
|
9
|
-
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
9
|
+
import { n as currentInboundRequest, p as reportTelegramError } from "../../../_chunks/inbound-request-BXhiIph-.mjs";
|
|
10
10
|
import { needsConfirmation } from "../confirmations.mjs";
|
|
11
11
|
import { OntologyActionNotPermitted, actionToolName, ontologyTools } from "../ontology-tools.mjs";
|
|
12
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-BB2uSGsI.mjs";
|
|
12
13
|
var AttachmentLifecycleNotPermitted = class extends Error {
|
|
13
14
|
code = "attachment_lifecycle_not_permitted";
|
|
14
15
|
};
|
|
15
16
|
function attachmentLifecycle(options) {
|
|
16
|
-
const
|
|
17
|
+
const source = () => options.message.raw === void 0 ? principalRuntimeSource(options.principal) : telegramRuntimeSource({
|
|
18
|
+
...options.message,
|
|
19
|
+
attachments: options.message.attachments ?? [],
|
|
20
|
+
raw: options.message.raw
|
|
21
|
+
}, currentInboundRequest()?.files);
|
|
17
22
|
const action = actionToolName(options.configuration.entity, options.configuration.action);
|
|
18
23
|
return async (phase, data = {}) => {
|
|
19
24
|
console.info("[segmentstream] telegram.phase", {
|
|
@@ -40,6 +45,13 @@ function attachmentLifecycle(options) {
|
|
|
40
45
|
...options.configuration.contextVersion === 2 && typeof options.message.raw?.date === "number" && Number.isSafeInteger(options.message.raw.date) && options.message.raw.date > 0 ? { source_at: options.message.raw.date * 1e3 } : {}
|
|
41
46
|
}
|
|
42
47
|
};
|
|
48
|
+
const tools = ontologyTools({
|
|
49
|
+
...options,
|
|
50
|
+
envelope: runtimeEnvelope({
|
|
51
|
+
principal: options.principal,
|
|
52
|
+
source: source()
|
|
53
|
+
})
|
|
54
|
+
});
|
|
43
55
|
const labels = await tools.labels(options.memberId, action, input).catch((error) => {
|
|
44
56
|
throw error instanceof OntologyActionNotPermitted ? new AttachmentLifecycleNotPermitted("The sender may not run the lifecycle action.", { cause: error }) : error;
|
|
45
57
|
});
|
|
@@ -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-
|
|
8
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-BXhiIph-.mjs";
|
|
9
9
|
function planMedia(capabilities, descriptionModel = null) {
|
|
10
10
|
if (typeof descriptionModel === "string") return {
|
|
11
11
|
images: "describe",
|
|
@@ -14,6 +14,7 @@ export declare function telegramPrincipal(input: {
|
|
|
14
14
|
};
|
|
15
15
|
readonly member: PairedMember;
|
|
16
16
|
readonly conversationLanguage?: string;
|
|
17
|
+
readonly callbackQueryId?: string;
|
|
17
18
|
}): SessionAuthContext;
|
|
18
19
|
/** Short answers and attachment-only turns retain the recent chat language when known. */
|
|
19
20
|
export declare function conversationLanguage(texts: readonly string[]): "ru" | "en" | undefined;
|
|
@@ -4,53 +4,5 @@ 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
|
-
|
|
8
|
-
function isGroup(message) {
|
|
9
|
-
return message.chat.type === "group" || message.chat.type === "supergroup";
|
|
10
|
-
}
|
|
11
|
-
function telegramPrincipal(input) {
|
|
12
|
-
const { message, member } = input;
|
|
13
|
-
const sender = message.from.id;
|
|
14
|
-
const attributes = {
|
|
15
|
-
memberId: member.id,
|
|
16
|
-
identityProvider: "telegram",
|
|
17
|
-
roles: member.roles,
|
|
18
|
-
chatId: message.chat.id,
|
|
19
|
-
chatType: message.chat.type
|
|
20
|
-
};
|
|
21
|
-
if (member.name !== null) attributes.memberName = member.name;
|
|
22
|
-
if (message.messageThreadId !== void 0) attributes.messageThreadId = String(message.messageThreadId);
|
|
23
|
-
if (message.from.username !== void 0) attributes.username = message.from.username;
|
|
24
|
-
const locale = member.locale ?? message.from.languageCode;
|
|
25
|
-
if (locale !== void 0) attributes.locale = locale;
|
|
26
|
-
const language = input.conversationLanguage ?? conversationLanguage([message.text || message.caption]);
|
|
27
|
-
if (language !== void 0) attributes.conversationLanguage = language;
|
|
28
|
-
return {
|
|
29
|
-
authenticator: TELEGRAM_AUTHENTICATOR,
|
|
30
|
-
issuer: "telegram",
|
|
31
|
-
principalId: isGroup(message) ? `telegram:${message.chat.id}:${sender}` : `telegram:${sender}`,
|
|
32
|
-
principalType: "user",
|
|
33
|
-
subject: sender,
|
|
34
|
-
attributes
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function conversationLanguage(texts) {
|
|
38
|
-
for (const text of texts) {
|
|
39
|
-
if (/[\u0430-\u044f\u0451]/iu.test(text)) return "ru";
|
|
40
|
-
if ((text.match(/\b[a-z]+\b/gi)?.length ?? 0) >= 3) return "en";
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function memberIdOf(principal) {
|
|
44
|
-
const memberId = principal?.attributes.memberId;
|
|
45
|
-
return typeof memberId === "string" && memberId !== "" ? memberId : void 0;
|
|
46
|
-
}
|
|
47
|
-
function rolesOf(principal) {
|
|
48
|
-
const roles = principal?.attributes.roles;
|
|
49
|
-
if (typeof roles === "string") return [roles];
|
|
50
|
-
return roles ?? [];
|
|
51
|
-
}
|
|
52
|
-
function identityProviderOf(principal) {
|
|
53
|
-
const provider = principal?.attributes.identityProvider;
|
|
54
|
-
return typeof provider === "string" && provider !== "" ? provider : void 0;
|
|
55
|
-
}
|
|
7
|
+
import { a as rolesOf, i as memberIdOf, n as conversationLanguage, o as telegramPrincipal, r as identityProviderOf, t as TELEGRAM_AUTHENTICATOR } from "../../../_chunks/principal-VFQWqe5S.mjs";
|
|
56
8
|
export { TELEGRAM_AUTHENTICATOR, conversationLanguage, identityProviderOf, memberIdOf, rolesOf, telegramPrincipal };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { TelegramMessage } from "eve/channels/telegram";
|
|
2
|
-
import type { CancelTurnResult } from "eve/channels";
|
|
2
|
+
import type { CancelTurnResult, ChannelSource } from "eve/channels";
|
|
3
|
+
import type { TelegramChannelState } from "eve/channels/telegram";
|
|
3
4
|
import type { SessionSettings } from "../../config.js";
|
|
4
5
|
/**
|
|
5
6
|
* Session policy for the Telegram channel (`agent-design.md`, section 4, and docs/agent.md,
|
|
@@ -62,6 +63,7 @@ export interface SessionOperations {
|
|
|
62
63
|
}) => Promise<CancelTurnResult>;
|
|
63
64
|
} | undefined>;
|
|
64
65
|
readonly from: (address: string) => {
|
|
66
|
+
readonly send?: ChannelSource<TelegramChannelState>["send"];
|
|
65
67
|
compact(): Promise<unknown>;
|
|
66
68
|
clear(): Promise<unknown>;
|
|
67
69
|
};
|
|
@@ -4,12 +4,12 @@ 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 "
|
|
8
|
-
import { agentMessage, observedChatKey } from "../group-routing/observed.mjs";
|
|
7
|
+
import "../../../_chunks/principal-VFQWqe5S.mjs";
|
|
9
8
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
10
9
|
import { splitTelegramText } from "./format.mjs";
|
|
11
10
|
import { inTelegramSendQueue } from "./send-queue.mjs";
|
|
12
|
-
import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
11
|
+
import { a as TelegramDeliveryError, l as customerMessage, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-BXhiIph-.mjs";
|
|
12
|
+
import { agentMessage, observedChatKey } from "../group-routing/observed.mjs";
|
|
13
13
|
const SILENT_MARKERS = new Set(["[silent]", "no_reply"]);
|
|
14
14
|
function isSilentReply(text) {
|
|
15
15
|
return SILENT_MARKERS.has(text.trim().toLowerCase());
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LocalizedText } from "../../config.js";
|
|
2
|
+
export declare const TELEGRAM_TEXT_KEYS: {
|
|
3
|
+
readonly callback: readonly ["error", "unknown", "forbidden", "expired", "already", "unsupported"];
|
|
4
|
+
readonly confirmation: readonly ["question", "confirm", "cancel", "edit", "executing", "done", "cancelled", "failed", "expired", "interrupted"];
|
|
5
|
+
readonly chatPost: readonly ["sent", "uncertain", "historyNotRecorded"];
|
|
6
|
+
readonly notice: readonly ["failed", "recovery", "attachment", "authorization", "response", "connected", "disconnected", "cancelled"];
|
|
7
|
+
readonly authorization: readonly ["prompt", "url", "button"];
|
|
8
|
+
};
|
|
9
|
+
export type TelegramTexts = {
|
|
10
|
+
readonly [Group in keyof typeof TELEGRAM_TEXT_KEYS]?: Partial<Record<(typeof TELEGRAM_TEXT_KEYS)[Group][number], LocalizedText>>;
|
|
11
|
+
};
|
|
12
|
+
/** Bind workspace copy to one webhook or durable event, never to another workspace's request. */
|
|
13
|
+
export declare function withTelegramTexts<T>(texts: TelegramTexts, run: () => T, locale?: () => string): T;
|
|
14
|
+
export declare function telegramText<Group extends keyof TelegramTexts>(group: Group, key: (typeof TELEGRAM_TEXT_KEYS)[Group][number], locale?: string): string | undefined;
|
|
15
|
+
/** A persisted card keeps its original locale even while another member's webhook reconciles it. */
|
|
16
|
+
export declare function withTelegramLocale<T>(locale: string | undefined, run: () => T): T;
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { AsyncLocalStorage } from "node:async_hooks";
|
|
9
|
+
const TELEGRAM_TEXT_KEYS = {
|
|
10
|
+
callback: [
|
|
11
|
+
"error",
|
|
12
|
+
"unknown",
|
|
13
|
+
"forbidden",
|
|
14
|
+
"expired",
|
|
15
|
+
"already",
|
|
16
|
+
"unsupported"
|
|
17
|
+
],
|
|
18
|
+
confirmation: [
|
|
19
|
+
"question",
|
|
20
|
+
"confirm",
|
|
21
|
+
"cancel",
|
|
22
|
+
"edit",
|
|
23
|
+
"executing",
|
|
24
|
+
"done",
|
|
25
|
+
"cancelled",
|
|
26
|
+
"failed",
|
|
27
|
+
"expired",
|
|
28
|
+
"interrupted"
|
|
29
|
+
],
|
|
30
|
+
chatPost: [
|
|
31
|
+
"sent",
|
|
32
|
+
"uncertain",
|
|
33
|
+
"historyNotRecorded"
|
|
34
|
+
],
|
|
35
|
+
notice: [
|
|
36
|
+
"failed",
|
|
37
|
+
"recovery",
|
|
38
|
+
"attachment",
|
|
39
|
+
"authorization",
|
|
40
|
+
"response",
|
|
41
|
+
"connected",
|
|
42
|
+
"disconnected",
|
|
43
|
+
"cancelled"
|
|
44
|
+
],
|
|
45
|
+
authorization: [
|
|
46
|
+
"prompt",
|
|
47
|
+
"url",
|
|
48
|
+
"button"
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
const storage = new AsyncLocalStorage();
|
|
52
|
+
function withTelegramTexts(texts, run, locale = () => "en") {
|
|
53
|
+
return storage.run({
|
|
54
|
+
texts,
|
|
55
|
+
locale
|
|
56
|
+
}, run);
|
|
57
|
+
}
|
|
58
|
+
function telegramText(group, key, locale) {
|
|
59
|
+
const configured = storage.getStore();
|
|
60
|
+
const section = configured?.texts[group];
|
|
61
|
+
return localizedText(section?.[key], locale ?? configured?.locale());
|
|
62
|
+
}
|
|
63
|
+
function withTelegramLocale(locale, run) {
|
|
64
|
+
const configured = storage.getStore();
|
|
65
|
+
return configured === void 0 || locale === void 0 ? run() : storage.run({
|
|
66
|
+
...configured,
|
|
67
|
+
locale: () => locale
|
|
68
|
+
}, run);
|
|
69
|
+
}
|
|
70
|
+
export { TELEGRAM_TEXT_KEYS, telegramText, withTelegramLocale, withTelegramTexts };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { TelegramChannelEvents } from "eve/channels/telegram";
|
|
2
|
-
export declare const telegramFailureEvents: Pick<TelegramChannelEvents, "turn.failed" | "turn.cancelled" | "session.failed" | "authorization.completed">;
|
|
2
|
+
export declare const telegramFailureEvents: Pick<TelegramChannelEvents, "turn.failed" | "turn.cancelled" | "session.failed" | "authorization.completed" | "authorization.required">;
|
|
@@ -4,11 +4,41 @@ 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 {
|
|
7
|
+
import { telegramText } from "./texts.mjs";
|
|
8
|
+
import { i as memberIdOf } from "../../../_chunks/principal-VFQWqe5S.mjs";
|
|
8
9
|
import { confirmationLocale } from "./confirmation-text.mjs";
|
|
9
|
-
import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-
|
|
10
|
+
import { c as customerCopy, d as failureText, o as currentLocale, p as reportTelegramError } from "../../../_chunks/inbound-request-BXhiIph-.mjs";
|
|
10
11
|
const telegramFailureEvents = {
|
|
12
|
+
async "authorization.required"(event, channel, context) {
|
|
13
|
+
if (event.candidateId !== void 0) return;
|
|
14
|
+
const locale = confirmationLocale(context.session.auth.current, currentLocale());
|
|
15
|
+
const prompt = telegramText("authorization", "prompt", locale);
|
|
16
|
+
const url = telegramText("authorization", "url", locale);
|
|
17
|
+
const button = telegramText("authorization", "button", locale);
|
|
18
|
+
if (prompt !== void 0) {
|
|
19
|
+
const sent = await channel.telegram.post({
|
|
20
|
+
text: prompt,
|
|
21
|
+
...url === void 0 || button === void 0 ? {} : { reply_markup: { inline_keyboard: [[{
|
|
22
|
+
text: button,
|
|
23
|
+
url
|
|
24
|
+
}]] } }
|
|
25
|
+
});
|
|
26
|
+
if (sent.id) channel.state.pendingAuthMessageIds = {
|
|
27
|
+
...channel.state.pendingAuthMessageIds,
|
|
28
|
+
[event.name]: sent.id
|
|
29
|
+
};
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const state = channel.state;
|
|
33
|
+
state.authorizationCancellationTurnId = event.turnId;
|
|
34
|
+
const errorId = reportTelegramError("authorization_prompt_unconfigured", new Error("texts.authorization.prompt is not configured."), { sessionId: context.session.id });
|
|
35
|
+
await channel.telegram.post(failureText(errorId, "authorization", locale));
|
|
36
|
+
},
|
|
11
37
|
async "turn.cancelled"(event, channel, context) {
|
|
38
|
+
const state = channel.state;
|
|
39
|
+
const authorizationTurn = state.authorizationCancellationTurnId;
|
|
40
|
+
delete state.authorizationCancellationTurnId;
|
|
41
|
+
if (typeof event.turnId === "string" && authorizationTurn === event.turnId) return;
|
|
12
42
|
const errorId = reportTelegramError("turn_cancelled", event, {
|
|
13
43
|
chatId: channel.state.chatId,
|
|
14
44
|
sessionId: context.session.id,
|
|
@@ -37,17 +67,21 @@ const telegramFailureEvents = {
|
|
|
37
67
|
const messageId = channel.state.pendingAuthMessageIds?.[event.name];
|
|
38
68
|
if (event.candidateId !== void 0 || messageId === void 0) return;
|
|
39
69
|
const locale = confirmationLocale(context.session.auth.current);
|
|
40
|
-
const copy = customerCopy();
|
|
70
|
+
const copy = customerCopy(locale);
|
|
41
71
|
let text = event.outcome === "authorized" ? copy.connected : copy.disconnected;
|
|
42
72
|
if (event.reason !== void 0) {
|
|
43
73
|
const errorId = reportTelegramError("authorization_not_completed", event, { chatId: channel.state.chatId });
|
|
44
74
|
text = failureText(errorId, "authorization", locale);
|
|
45
75
|
}
|
|
46
|
-
await channel.telegram.editMessageText({
|
|
76
|
+
if (text !== void 0) await channel.telegram.editMessageText({
|
|
47
77
|
messageId,
|
|
48
78
|
text,
|
|
49
79
|
replyMarkup: { inline_keyboard: [] }
|
|
50
80
|
});
|
|
81
|
+
else await channel.telegram.editMessageReplyMarkup({
|
|
82
|
+
messageId,
|
|
83
|
+
replyMarkup: { inline_keyboard: [] }
|
|
84
|
+
});
|
|
51
85
|
delete channel.state.pendingAuthMessageIds?.[event.name];
|
|
52
86
|
}
|
|
53
87
|
};
|
|
@@ -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-
|
|
7
|
+
import { p as reportTelegramError } from "../../../_chunks/inbound-request-BXhiIph-.mjs";
|
|
8
8
|
import "../connection-proxy.mjs";
|
|
9
9
|
import { gateway, transcribe } from "ai";
|
|
10
10
|
const LABELS = {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SessionAuthContext } from "eve/context";
|
|
2
|
+
import type { RuntimeEnvelope } from "../runtime-envelope.js";
|
|
3
|
+
import type { Environment } from "../environment.js";
|
|
4
|
+
import type { RuntimeToken } from "../runtime-token.js";
|
|
5
|
+
export interface WorkspaceActionHook {
|
|
6
|
+
readonly entity: string;
|
|
7
|
+
readonly action: string;
|
|
8
|
+
readonly contextVersion: 2;
|
|
9
|
+
}
|
|
10
|
+
/** A declared routine action, re-authorized as the verified member on every event. */
|
|
11
|
+
export declare function workspaceAction(input: {
|
|
12
|
+
readonly configuration: WorkspaceActionHook;
|
|
13
|
+
readonly principal: SessionAuthContext;
|
|
14
|
+
readonly memberId: string;
|
|
15
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
16
|
+
readonly envelope: RuntimeEnvelope;
|
|
17
|
+
readonly environment?: Environment;
|
|
18
|
+
readonly token?: RuntimeToken;
|
|
19
|
+
readonly fetch?: typeof fetch;
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
}): Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { object } from "../confirmation-description.mjs";
|
|
8
|
+
import { needsConfirmation } from "../confirmations.mjs";
|
|
9
|
+
import { actionToolName, ontologyTools } from "../ontology-tools.mjs";
|
|
10
|
+
async function workspaceAction(input) {
|
|
11
|
+
const tools = ontologyTools(input);
|
|
12
|
+
const action = actionToolName(input.configuration.entity, input.configuration.action);
|
|
13
|
+
if (needsConfirmation(await tools.labels(input.memberId, action, input.input, input.signal))) throw new Error("A Telegram workspace hook must be a permitted routine action.");
|
|
14
|
+
if (!await tools.supportsRuntimeSource(input.memberId, input.signal)) throw new Error("A Telegram workspace hook requires the runtime-source capability.");
|
|
15
|
+
const raw = await tools.rpc(input.memberId, "tools/call", {
|
|
16
|
+
name: action,
|
|
17
|
+
arguments: input.input
|
|
18
|
+
}, input.signal);
|
|
19
|
+
const envelope = object(raw.structuredContent);
|
|
20
|
+
if (object(envelope.validation).ok === false) throw new Error("The Telegram workspace hook rejected its event.");
|
|
21
|
+
return object(envelope.result ?? envelope);
|
|
22
|
+
}
|
|
23
|
+
export { workspaceAction };
|
package/dist/extension/model.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { isPreview } from "./lib/environment.mjs";
|
|
8
|
-
import { rolesOf } from "
|
|
8
|
+
import { a as rolesOf } from "../_chunks/principal-VFQWqe5S.mjs";
|
|
9
9
|
import { defineDynamic } from "eve";
|
|
10
10
|
function chooseModel(input) {
|
|
11
11
|
const { choice } = input;
|
|
@@ -4,13 +4,16 @@ 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 { u as runtimeEnvelope } from "../../_chunks/principal-VFQWqe5S.mjs";
|
|
7
8
|
import { n as workflowToolResult } from "../../_chunks/workflow-serializable-DVQBWK8p.mjs";
|
|
9
|
+
import segmentstream from "../extension.mjs";
|
|
8
10
|
import { actionApproval } from "../lib/confirmations.mjs";
|
|
9
11
|
import { ontologyTools, promotionTarget } from "../lib/ontology-tools.mjs";
|
|
10
12
|
import { attachmentForModel, attachmentOwner, optionalObject, optionalString, stringArgument, toolAttachments } from "../lib/attachment-tools.mjs";
|
|
11
13
|
import { defineTool } from "eve/tools";
|
|
12
14
|
var attachments_promote_default = defineTool({
|
|
13
15
|
approval: actionApproval({
|
|
16
|
+
texts: () => segmentstream.config.texts ?? {},
|
|
14
17
|
labels: (memberId, _tool, input) => {
|
|
15
18
|
const target = promotionTarget(input);
|
|
16
19
|
return ontologyTools().labels(memberId, target.action, target.input);
|
|
@@ -71,6 +74,11 @@ var attachments_promote_default = defineTool({
|
|
|
71
74
|
const recordId = optionalString(input, "record_id");
|
|
72
75
|
const actionInput = optionalObject(input, "input");
|
|
73
76
|
const promoted = await toolAttachments().promote(owner, stringArgument(input, "id"), {
|
|
77
|
+
runtime: runtimeEnvelope({
|
|
78
|
+
principal: ctx.session.auth.current,
|
|
79
|
+
sessionId: ctx.session.id,
|
|
80
|
+
callId: ctx.callId
|
|
81
|
+
}),
|
|
74
82
|
entity: stringArgument(input, "entity"),
|
|
75
83
|
action: stringArgument(input, "action"),
|
|
76
84
|
...actionInput === void 0 ? {} : { input: actionInput },
|
|
@@ -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 { memberIdOf } from "
|
|
7
|
+
import { i as memberIdOf } from "../../_chunks/principal-VFQWqe5S.mjs";
|
|
8
8
|
import segmentstream from "../extension.mjs";
|
|
9
9
|
import { executeDeferredTool } from "../lib/deferred-confirmations.mjs";
|
|
10
10
|
import { ontologyInspect, ontologyMetadata } from "../lib/ontology-gateway.mjs";
|
|
@@ -123,7 +123,7 @@ var ontology_default = defineDynamic({ events: { "turn.started": async (_event,
|
|
|
123
123
|
required: ["name"],
|
|
124
124
|
additionalProperties: false
|
|
125
125
|
},
|
|
126
|
-
execute: (input, ctx) => executeDeferredTool(memberId, input.name, input.arguments ?? {}, ctx)
|
|
126
|
+
execute: (input, ctx) => executeDeferredTool(memberId, input.name, input.arguments ?? {}, ctx, { texts: () => segmentstream.config.texts ?? {} })
|
|
127
127
|
})
|
|
128
128
|
};
|
|
129
129
|
} } });
|
|
@@ -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 { memberIdOf } from "
|
|
7
|
+
import { i as memberIdOf } from "../../_chunks/principal-VFQWqe5S.mjs";
|
|
8
8
|
import { n as workflowToolResult } from "../../_chunks/workflow-serializable-DVQBWK8p.mjs";
|
|
9
9
|
import { pendingQuestions, questionKey } from "../lib/questions.mjs";
|
|
10
10
|
import { stringArgument } from "../lib/attachment-tools.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Mount a SegmentStream workspace's agent on eve: the ontology as tools, acting as the member who writes, and Telegram through the workspace's connection.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"@chat-adapter/telegram": "4.41.0",
|
|
65
|
-
"@segmentstream-cloud/ontology": "0.
|
|
65
|
+
"@segmentstream-cloud/ontology": "0.50.0",
|
|
66
66
|
"@vercel/oidc": "^3.8.4",
|
|
67
67
|
"ai": "^7.0.128",
|
|
68
68
|
"csv-parse": "^7.0.3",
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `segmentstream__ontology`: the ontology's MCP tools, acting as the member of each turn. It is
|
|
3
|
-
* resolved per turn because a group chat's session serves several members; a turn without a
|
|
4
|
-
* paired member, or a mount with `ontology.connection: false`, gets no connection.
|
|
5
|
-
*/
|
|
6
|
-
declare const _default: import("eve").DynamicSentinel<import("eve/connections").DynamicConnectionResult>;
|
|
7
|
-
export default _default;
|
|
@@ -1,11 +0,0 @@
|
|
|
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 segmentstream from "../extension.mjs";
|
|
8
|
-
import { ontologyConnectionForTurn } from "../lib/ontology-connection.mjs";
|
|
9
|
-
import { defineDynamic } from "eve/connections";
|
|
10
|
-
var ontology_default = defineDynamic({ events: { "turn.started": (_event, context) => segmentstream.config.ontology.connection && segmentstream.config.confirmations.mode === "held" ? ontologyConnectionForTurn({ principal: context.session.auth.current }) : null } });
|
|
11
|
-
export { ontology_default as default };
|