@segmentstream/agent 0.36.2 → 0.36.3
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/dist/_chunks/{build-metadata-Cmrq0o5K.mjs → build-metadata-D3ytCxvV.mjs} +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/confirmation-buttons.d.ts +22 -0
- package/dist/extension/lib/confirmation-buttons.mjs +44 -0
- package/dist/extension/lib/confirmations.d.ts +2 -0
- package/dist/extension/lib/confirmations.mjs +12 -1
- package/dist/extension/lib/slack/adapter.mjs +3 -1
- package/dist/extension/lib/telegram/adapter.mjs +1 -1
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/lifecycle.mjs +1 -1
- package/dist/extension/lib/whatsapp/adapter.mjs +6 -1
- package/package.json +1 -1
|
@@ -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.36.
|
|
7
|
+
var version = "0.36.3";
|
|
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-D3ytCxvV.mjs";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SessionAuthContext } from "eve/context";
|
|
2
|
+
/** Whether the card's whole text fits the channel's approval card; a card is never cut. */
|
|
3
|
+
export declare function promptFits(identityProvider: unknown, text: string): boolean;
|
|
4
|
+
/** One answer a channel decoded from a click on eve's own input buttons. */
|
|
5
|
+
export interface ButtonAnswer {
|
|
6
|
+
readonly interactionId: string;
|
|
7
|
+
readonly optionId?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The responder's principal, stamped with the decision a click on a confirmation's own button
|
|
11
|
+
* carried, as the Telegram callback stamps it. The response policy accepts an approval or a
|
|
12
|
+
* cancellation only with this stamp, so a typed message never decides a confirmation.
|
|
13
|
+
*
|
|
14
|
+
* Only a click that answers exactly one request with approve or deny is stamped; anything else,
|
|
15
|
+
* such as a question's answers, keeps the plain principal.
|
|
16
|
+
*/
|
|
17
|
+
export declare function withButtonDecision(principal: SessionAuthContext, answers: readonly ButtonAnswer[]): SessionAuthContext;
|
|
18
|
+
/**
|
|
19
|
+
* The answer in a Chat SDK action for one of eve's own input buttons. eve names each button
|
|
20
|
+
* `<prefix><encoded interaction id>:<encoded option id>` and carries the option id as its value.
|
|
21
|
+
*/
|
|
22
|
+
export declare function chatSdkButtonAnswer(actionId: string, value: string | undefined, prefix?: string): ButtonAnswer | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
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 { APPROVE_OPTION_ID, DENY_OPTION_ID } from "eve/events";
|
|
8
|
+
const PROMPT_LIMITS = {
|
|
9
|
+
whatsapp: 1e3,
|
|
10
|
+
slack: 2900
|
|
11
|
+
};
|
|
12
|
+
function promptFits(identityProvider, text) {
|
|
13
|
+
const limit = typeof identityProvider === "string" ? PROMPT_LIMITS[identityProvider] : void 0;
|
|
14
|
+
return limit === void 0 || text.length <= limit;
|
|
15
|
+
}
|
|
16
|
+
function withButtonDecision(principal, answers) {
|
|
17
|
+
const [answer] = answers;
|
|
18
|
+
if (answers.length !== 1 || answer === void 0 || answer.optionId !== APPROVE_OPTION_ID && answer.optionId !== DENY_OPTION_ID) return principal;
|
|
19
|
+
return {
|
|
20
|
+
...principal,
|
|
21
|
+
attributes: {
|
|
22
|
+
...principal.attributes,
|
|
23
|
+
confirmationRequestId: answer.interactionId,
|
|
24
|
+
confirmationDecision: answer.optionId === DENY_OPTION_ID ? "cancel" : "approve"
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function chatSdkButtonAnswer(actionId, value, prefix = "eve_input:") {
|
|
29
|
+
if (!actionId.startsWith(prefix)) return;
|
|
30
|
+
const rest = actionId.slice(prefix.length);
|
|
31
|
+
const separator = rest.indexOf(":");
|
|
32
|
+
if (separator <= 0) return;
|
|
33
|
+
try {
|
|
34
|
+
const interactionId = decodeURIComponent(rest.slice(0, separator));
|
|
35
|
+
const optionId = decodeURIComponent(rest.slice(separator + 1));
|
|
36
|
+
return value === void 0 || value === optionId ? {
|
|
37
|
+
interactionId,
|
|
38
|
+
optionId
|
|
39
|
+
} : void 0;
|
|
40
|
+
} catch {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export { chatSdkButtonAnswer, promptFits, withButtonDecision };
|
|
@@ -26,6 +26,8 @@ export interface Confirmation {
|
|
|
26
26
|
readonly status: "pending" | "approved" | "consumed" | "cancelled";
|
|
27
27
|
readonly description?: ConfirmationDescription;
|
|
28
28
|
readonly copy?: ConfirmationCopy;
|
|
29
|
+
/** The card's text, which channels that show eve's own approval card show as its prompt. */
|
|
30
|
+
readonly prompt?: string;
|
|
29
31
|
readonly source?: {
|
|
30
32
|
readonly chatId: string;
|
|
31
33
|
readonly threadId: string;
|
|
@@ -8,6 +8,7 @@ import { actorOf, member } from "./actor.mjs";
|
|
|
8
8
|
import { i as memberIdOf } from "../../_chunks/principal-UlkbLrgQ.mjs";
|
|
9
9
|
import { ConfirmationRefused, UnsafeConfirmationTarget } from "./confirmation-description.mjs";
|
|
10
10
|
import { chatPostDigest, isChatPost } from "./chat-post-confirmation.mjs";
|
|
11
|
+
import { promptFits } from "./confirmation-buttons.mjs";
|
|
11
12
|
import { confirmationCopy, confirmationCopyIssue, confirmationLocale, renderConfirmation } from "./telegram/confirmation-text.mjs";
|
|
12
13
|
import { chatPostCard } from "./telegram/chat-post-card.mjs";
|
|
13
14
|
import { withTelegramTexts } from "./telegram/texts.mjs";
|
|
@@ -40,6 +41,13 @@ function actionApproval(options) {
|
|
|
40
41
|
reason
|
|
41
42
|
});
|
|
42
43
|
return {
|
|
44
|
+
prompt({ callId }) {
|
|
45
|
+
try {
|
|
46
|
+
return state.get()[callId]?.prompt;
|
|
47
|
+
} catch {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
43
51
|
async request(ctx) {
|
|
44
52
|
const actor = actorOf(ctx.session.auth.current);
|
|
45
53
|
if (actor?.kind === "task") {
|
|
@@ -120,11 +128,13 @@ function actionApproval(options) {
|
|
|
120
128
|
...description,
|
|
121
129
|
warning: labels.destructiveHint === true || labels.irreversibleHint === true
|
|
122
130
|
};
|
|
131
|
+
let prompt;
|
|
123
132
|
try {
|
|
124
|
-
if (!posting) present(() => renderConfirmation(description, copy));
|
|
133
|
+
if (!posting) prompt = present(() => renderConfirmation(description, copy)).text;
|
|
125
134
|
} catch {
|
|
126
135
|
return denied("The complete confirmation facts are unsafe or too long. Narrow the action input.");
|
|
127
136
|
}
|
|
137
|
+
if (prompt !== void 0 && !promptFits(ctx.session.auth.current?.attributes.identityProvider, prompt)) return denied("The complete confirmation facts are too long for this chat's confirmation card. Narrow the action input.");
|
|
128
138
|
state.update((all) => ({
|
|
129
139
|
...all,
|
|
130
140
|
[ctx.callId]: {
|
|
@@ -135,6 +145,7 @@ function actionApproval(options) {
|
|
|
135
145
|
status: "pending",
|
|
136
146
|
...copy === void 0 ? {} : { copy },
|
|
137
147
|
...description === void 0 ? {} : { description },
|
|
148
|
+
...prompt === void 0 ? {} : { prompt },
|
|
138
149
|
...posting ? { source: {
|
|
139
150
|
chatId: String(ctx.session.auth.current?.attributes.chatId),
|
|
140
151
|
threadId: String(ctx.session.auth.current?.attributes.messageThreadId ?? "")
|
|
@@ -5,6 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { admitMessage, localizedText } from "../admission.mjs";
|
|
8
|
+
import { withButtonDecision } from "../confirmation-buttons.mjs";
|
|
8
9
|
import { redactDiagnostic } from "../diagnostics.mjs";
|
|
9
10
|
import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs";
|
|
10
11
|
import { appOrigin, channelsEnabled, proxyEnvironment, webhookSecret } from "../environment.mjs";
|
|
@@ -144,7 +145,8 @@ function segmentstreamSlack(options) {
|
|
|
144
145
|
},
|
|
145
146
|
onAnswers: async (_ctx, submission) => {
|
|
146
147
|
const auth = await pairedPrincipal(submission.user.id);
|
|
147
|
-
|
|
148
|
+
if (auth === null) return null;
|
|
149
|
+
return { auth: submission.type === "block_actions" ? withButtonDecision(auth, submission.answers) : auth };
|
|
148
150
|
}
|
|
149
151
|
});
|
|
150
152
|
return {
|
|
@@ -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-D3ytCxvV.mjs";
|
|
14
14
|
import { attachmentLifecycle } from "./lifecycle.mjs";
|
|
15
15
|
import { manifestOf } from "../../config.mjs";
|
|
16
16
|
import { gatewayAttachmentDescriber } from "./attachment-description.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 { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
7
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-D3ytCxvV.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";
|
|
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { d as telegramRuntimeSource, l as principalRuntimeSource, u as runtimeEnvelope } from "../../../_chunks/principal-UlkbLrgQ.mjs";
|
|
8
|
-
import { t as agentBuild } from "../../../_chunks/build-metadata-
|
|
8
|
+
import { t as agentBuild } from "../../../_chunks/build-metadata-D3ytCxvV.mjs";
|
|
9
9
|
import { n as currentInboundRequest } from "../../../_chunks/inbound-request-DgQB4g1J.mjs";
|
|
10
10
|
import { object } from "../confirmation-description.mjs";
|
|
11
11
|
import { needsConfirmation } from "../confirmations.mjs";
|
|
@@ -5,6 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
|
|
|
5
5
|
__eveDirname(__filename);
|
|
6
6
|
__eveCreateRequire(import.meta.url);
|
|
7
7
|
import { admitMessage, localizedText } from "../admission.mjs";
|
|
8
|
+
import { chatSdkButtonAnswer, withButtonDecision } from "../confirmation-buttons.mjs";
|
|
8
9
|
import { redactDiagnostic } from "../diagnostics.mjs";
|
|
9
10
|
import { MAXIMUM_DOWNLOAD_BYTES, connectionProxy } from "../connection-proxy.mjs";
|
|
10
11
|
import { appOrigin, channelsEnabled, proxyEnvironment, webhookSecret } from "../environment.mjs";
|
|
@@ -160,7 +161,11 @@ function segmentstreamWhatsApp(options) {
|
|
|
160
161
|
adapters: { whatsapp: new ProxiedWhatsAppAdapter(runtime) },
|
|
161
162
|
state: createMemoryState(),
|
|
162
163
|
streaming: false,
|
|
163
|
-
resolveInputAuth: (event) =>
|
|
164
|
+
resolveInputAuth: async (event) => {
|
|
165
|
+
const principal = event.user?.userId === void 0 ? null : await pairedPrincipal(event.user.userId);
|
|
166
|
+
const answer = chatSdkButtonAnswer(event.actionId, event.value);
|
|
167
|
+
return principal === null || answer === void 0 ? principal : withButtonDecision(principal, [answer]);
|
|
168
|
+
}
|
|
164
169
|
});
|
|
165
170
|
bridge.bot.onDirectMessage((thread, message) => receive({
|
|
166
171
|
thread,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segmentstream/agent",
|
|
3
|
-
"version": "0.36.
|
|
3
|
+
"version": "0.36.3",
|
|
4
4
|
"description": "Mount a SegmentStream workspace's agent on eve: the ontology as tools, acting as the member who writes, and Telegram, WhatsApp and Slack through the workspace's connections.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "SegmentStream",
|