@segmentstream/agent 0.68.0 → 0.68.1
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 +4 -0
- package/dist/_chunks/{build-metadata-BgLeaVNH.mjs → build-metadata-uZJeSn-O.mjs} +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/telegram/adapter.mjs +1 -1
- package/dist/extension/lib/telegram/confirmations.d.ts +16 -0
- package/dist/extension/lib/telegram/confirmations.mjs +29 -1
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +14 -2
- package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.68.1
|
|
4
|
+
|
|
5
|
+
A member's typed answer settles an open usage-limit question in Telegram. While a chat's session waits on one, a message that is its answer (`1` or `2`, the option's id or label, or the workspace's `texts.usageLimit` button words, ignoring a leading mention and case) answers it as its buttons do and starts no turn. Eve resolved typed text against the question only in some deliveries, so in a group a typed `1` waited behind the question it was meant to answer.
|
|
6
|
+
|
|
3
7
|
## 0.68.0
|
|
4
8
|
|
|
5
9
|
The agent can search the web. `"web": { "search": true }` in `agent/segmentstream.json` gives
|
|
@@ -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.68.
|
|
7
|
+
var version = "0.68.1";
|
|
8
8
|
function agentBuild(environment = process.env) {
|
|
9
9
|
return {
|
|
10
10
|
agent: version,
|
|
@@ -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-uZJeSn-O.mjs";
|
|
@@ -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-
|
|
13
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-uZJeSn-O.mjs";
|
|
14
14
|
import { attachmentLifecycle } from "./lifecycle.mjs";
|
|
15
15
|
import { manifestOf } from "../../config.mjs";
|
|
16
16
|
import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
|
|
@@ -8,6 +8,22 @@ import { type HistoryReader, type RecordedEvent } from "./sessions.js";
|
|
|
8
8
|
export declare function confirmationCallback(requestId: string, memberId: string, decision: "approve" | "cancel" | "edit"): string;
|
|
9
9
|
/** A usage-limit button's callback: the question it answers and whether the session goes on. */
|
|
10
10
|
export declare function usageLimitCallback(interactionId: string, decision: "continue" | "stop"): string;
|
|
11
|
+
/** The latest usage-limit question of a session still waiting for an answer, with its options. */
|
|
12
|
+
export declare function openUsageLimit(events: readonly RecordedEvent[]): {
|
|
13
|
+
readonly interactionId: string;
|
|
14
|
+
readonly options: readonly {
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
}[];
|
|
18
|
+
} | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Whether a typed message answers a usage-limit question: its option number, id or label, or the
|
|
21
|
+
* workspace's button words, ignoring a leading mention and case. Anything else is no answer.
|
|
22
|
+
*/
|
|
23
|
+
export declare function usageLimitAnswer(text: string, options: readonly {
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
}[], locale?: string): "approve" | "cancel" | undefined;
|
|
11
27
|
/** Terminal facts override stale presentation, including when a Telegram edit failed. */
|
|
12
28
|
export declare function routingConfirmationState(events: readonly RecordedEvent[], prompt: ConfirmationPrompt, at: string): NonNullable<PendingConfirmation["state"]>;
|
|
13
29
|
/** Read-only projection of the same durable approval lifecycle used by the callback gate. */
|
|
@@ -33,6 +33,34 @@ function confirmationCallback(requestId, memberId, decision) {
|
|
|
33
33
|
function usageLimitCallback(interactionId, decision) {
|
|
34
34
|
return `${LIMIT_PREFIX}${shortHash(interactionId)}:${decision === "continue" ? "y" : "n"}`;
|
|
35
35
|
}
|
|
36
|
+
function openUsageLimit(events) {
|
|
37
|
+
const interactionId = openUsageLimits(events).at(-1);
|
|
38
|
+
if (interactionId === void 0) return;
|
|
39
|
+
const options = object(object(events.findLast((event) => event.type === "interaction.opened" && object(event.data).interactionId === interactionId)?.data).request).options;
|
|
40
|
+
return {
|
|
41
|
+
interactionId,
|
|
42
|
+
options: Array.isArray(options) ? options.flatMap((option) => {
|
|
43
|
+
const { id, label } = object(option);
|
|
44
|
+
return typeof id === "string" && typeof label === "string" ? [{
|
|
45
|
+
id,
|
|
46
|
+
label
|
|
47
|
+
}] : [];
|
|
48
|
+
}) : []
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function usageLimitAnswer(text, options, locale) {
|
|
52
|
+
const typed = text.replace(/^@\w+\s*/u, "").trim().replace(/[.!]+$/u, "").toLowerCase();
|
|
53
|
+
if (typed === "") return;
|
|
54
|
+
const words = (id, key, position) => [
|
|
55
|
+
position,
|
|
56
|
+
id,
|
|
57
|
+
options.find((option) => option.id === id)?.label,
|
|
58
|
+
telegramText("usageLimit", key, locale),
|
|
59
|
+
telegramText("usageLimit", key, "en")
|
|
60
|
+
].flatMap((word) => word === void 0 ? [] : [word.trim().toLowerCase()]);
|
|
61
|
+
if (words("approve", "continue", "1").includes(typed)) return "approve";
|
|
62
|
+
if (words("deny", "stop", "2").includes(typed)) return "cancel";
|
|
63
|
+
}
|
|
36
64
|
function openUsageLimits(events) {
|
|
37
65
|
const open = new Set();
|
|
38
66
|
for (const event of events) {
|
|
@@ -618,4 +646,4 @@ function telegramConfirmationEvents(archive, scope) {
|
|
|
618
646
|
};
|
|
619
647
|
}
|
|
620
648
|
const confirmationEvents = telegramConfirmationEvents();
|
|
621
|
-
export { confirmationCallback, confirmationEvents, handleConfirmationCallback, questionAddress, questionFromHistory, questionsFromHistory, refusalReason, routingConfirmationState, routingConfirmations, telegramConfirmationEvents, usageLimitCallback };
|
|
649
|
+
export { confirmationCallback, confirmationEvents, handleConfirmationCallback, openUsageLimit, questionAddress, questionFromHistory, questionsFromHistory, refusalReason, routingConfirmationState, routingConfirmations, telegramConfirmationEvents, usageLimitAnswer, usageLimitCallback };
|
|
@@ -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-uZJeSn-O.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";
|
|
@@ -16,7 +16,7 @@ import { questionInvitation } from "../group-routing/engagement.mjs";
|
|
|
16
16
|
import { AttachmentLifecycleNotPermitted } from "./lifecycle.mjs";
|
|
17
17
|
import { admitMessage, localizedText } from "../admission.mjs";
|
|
18
18
|
import { chatContext } from "../chats.mjs";
|
|
19
|
-
import { questionAddress, questionFromHistory } from "./confirmations.mjs";
|
|
19
|
+
import { openUsageLimit, questionAddress, questionFromHistory, usageLimitAnswer } from "./confirmations.mjs";
|
|
20
20
|
import { answerMarker } from "../questions.mjs";
|
|
21
21
|
import { inboundAttachments, stageFiles, telegramChat } from "./files.mjs";
|
|
22
22
|
import { MAXIMUM_NATIVE_IMAGE_BYTES } from "../inbound-media/images.mjs";
|
|
@@ -528,8 +528,20 @@ async function handleInboundMessage(input) {
|
|
|
528
528
|
};
|
|
529
529
|
const memberQuestionAddress = questionAddress(questionOwner);
|
|
530
530
|
const questionSession = await operations?.resolveSession(memberQuestionAddress);
|
|
531
|
-
const
|
|
531
|
+
const addressSession = questionSession === void 0 ? await operations?.resolveSession(address) : void 0;
|
|
532
|
+
const owner = questionSession ?? addressSession ?? await operations?.resolveSession(topicAddress);
|
|
533
|
+
const ownerAddress = questionSession !== void 0 ? memberQuestionAddress : addressSession !== void 0 ? address : topicAddress;
|
|
532
534
|
const questionHistory = owner === void 0 || dependencies.history === void 0 ? [] : await dependencies.history(owner.id);
|
|
535
|
+
const limit = owner === void 0 ? void 0 : openUsageLimit(questionHistory);
|
|
536
|
+
const limitAnswer = limit === void 0 ? void 0 : usageLimitAnswer(sent.text ?? "", limit.options, input.request?.locale);
|
|
537
|
+
if (limit !== void 0 && limitAnswer !== void 0 && input.request?.respond !== void 0) {
|
|
538
|
+
await input.request.respond(ownerAddress, limit.interactionId, limitAnswer, telegramPrincipal({
|
|
539
|
+
message: sent,
|
|
540
|
+
member
|
|
541
|
+
}));
|
|
542
|
+
recordGateDecision("usage_limit_answered");
|
|
543
|
+
return null;
|
|
544
|
+
}
|
|
533
545
|
await report;
|
|
534
546
|
const policySignals = telegramSignals(sent, bot, dependencies.signalSettings);
|
|
535
547
|
const groups = effectiveGroupPolicy(dependencies.groups ?? groupPolicy({}, {
|
|
@@ -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, Ft as principalRuntimeSource, It as runtimeEnvelope, L as needsConfirmation, Lt as telegramRuntimeSource, W as member, c as currentInboundRequest, j as ontologyTools, k as actionToolName } from "../../../_chunks/principal-DYl7vqOp.mjs";
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
8
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-uZJeSn-O.mjs";
|
|
9
9
|
import { object } from "../confirmation-description.mjs";
|
|
10
10
|
var AttachmentLifecycleNotPermitted = class extends Error {
|
|
11
11
|
code = "attachment_lifecycle_not_permitted";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.68.
|
|
3
|
+
"version": "0.68.1",
|
|
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",
|