arisa 4.1.12 → 4.1.14
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/package.json
CHANGED
|
@@ -57,6 +57,8 @@ async function promptAndThrowOnAssistantError(session, prompt) {
|
|
|
57
57
|
|
|
58
58
|
function inferDeliveryMethod(artifact) {
|
|
59
59
|
if (artifact.kind === "audio" || (artifact.mimeType || "").startsWith("audio/")) return "audio";
|
|
60
|
+
if (artifact.kind === "image" || (artifact.mimeType || "").startsWith("image/")) return "photo";
|
|
61
|
+
if (artifact.kind === "video" || (artifact.mimeType || "").startsWith("video/")) return "video";
|
|
60
62
|
return "document";
|
|
61
63
|
}
|
|
62
64
|
|
|
@@ -48,7 +48,23 @@ function getIncomingMessageText(message) {
|
|
|
48
48
|
return message?.text || message?.caption || "";
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
function
|
|
51
|
+
function baseMimeType(mimeType = "") {
|
|
52
|
+
return mimeType.split(";")[0].trim().toLowerCase();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function isInlineTextArtifact(artifact, messageText) {
|
|
56
|
+
return artifact?.kind === "text"
|
|
57
|
+
&& baseMimeType(artifact.mimeType) === "text/plain"
|
|
58
|
+
&& typeof artifact.text === "string"
|
|
59
|
+
&& artifact.text === messageText;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function shouldIncludeArtifactReference({ artifact, messageText = "" } = {}) {
|
|
63
|
+
if (!artifact) return false;
|
|
64
|
+
return !isInlineTextArtifact(artifact, messageText);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function buildPrompt({ ctx, artifact, transcript, toolResult }) {
|
|
52
68
|
const parts = [
|
|
53
69
|
`Incoming Telegram message.`,
|
|
54
70
|
`chatId: ${ctx.chat.id}`,
|
|
@@ -60,10 +76,12 @@ function buildPrompt({ ctx, artifact, transcript, toolResult }) {
|
|
|
60
76
|
const messageText = getIncomingMessageText(ctx.message);
|
|
61
77
|
if (messageText) parts.push(`text: ${messageText}`);
|
|
62
78
|
parts.push(...quotedMessageSummary(ctx.message?.reply_to_message));
|
|
63
|
-
if (artifact
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
79
|
+
if (shouldIncludeArtifactReference({ artifact, messageText })) {
|
|
80
|
+
if (artifact?.path) parts.push(`artifactPath: ${artifact.path}`);
|
|
81
|
+
if (artifact?.id) parts.push(`artifactId: ${artifact.id}`);
|
|
82
|
+
if (artifact?.mimeType) parts.push(`mimeType: ${artifact.mimeType}`);
|
|
83
|
+
if (artifact?.kind) parts.push(`kind: ${artifact.kind}`);
|
|
84
|
+
}
|
|
67
85
|
if (transcript) {
|
|
68
86
|
parts.push(`transcriptArtifactId: ${transcript.id}`);
|
|
69
87
|
parts.push(`transcriptText: ${transcript.text}`);
|
|
@@ -91,21 +109,24 @@ function buildNewSessionPrompt(ctx) {
|
|
|
91
109
|
}
|
|
92
110
|
|
|
93
111
|
async function buildAsyncTaskPrompt({ task, artifactStore, toolRegistry, logger }) {
|
|
112
|
+
const taskText = task.payload.prompt || "";
|
|
94
113
|
const parts = [
|
|
95
114
|
"Scheduled task fired.",
|
|
96
115
|
`taskId: ${task.id}`,
|
|
97
116
|
`chatId: ${task.payload.chatId}`,
|
|
98
|
-
|
|
117
|
+
taskText ? `text: ${taskText}` : null
|
|
99
118
|
];
|
|
100
119
|
|
|
101
120
|
if (task.payload.artifactId) {
|
|
102
121
|
const chatArtifactStore = artifactStore.forChat(task.payload.chatId);
|
|
103
122
|
const artifact = await chatArtifactStore.get(task.payload.artifactId);
|
|
104
123
|
if (artifact) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
124
|
+
if (shouldIncludeArtifactReference({ artifact, messageText: taskText })) {
|
|
125
|
+
parts.push(`artifactPath: ${artifact.path || ""}`);
|
|
126
|
+
parts.push(`artifactId: ${artifact.id}`);
|
|
127
|
+
parts.push(`mimeType: ${artifact.mimeType}`);
|
|
128
|
+
parts.push(`kind: ${artifact.kind}`);
|
|
129
|
+
}
|
|
109
130
|
|
|
110
131
|
const { normalizedArtifact, toolResult } = await normalizeArtifactForReasoning({
|
|
111
132
|
artifact,
|
|
@@ -431,6 +452,8 @@ export async function createTelegramBot({ config, artifactStore, toolRegistry, t
|
|
|
431
452
|
const input = new InputFile(filePath, filename || undefined);
|
|
432
453
|
if (method === "voice") return bot.api.sendVoice(chatId, input, { caption });
|
|
433
454
|
if (method === "document") return bot.api.sendDocument(chatId, input, { caption });
|
|
455
|
+
if (method === "photo" || method === "image") return bot.api.sendPhoto(chatId, input, { caption });
|
|
456
|
+
if (method === "video") return bot.api.sendVideo(chatId, input, { caption });
|
|
434
457
|
return bot.api.sendAudio(chatId, input, { caption });
|
|
435
458
|
}
|
|
436
459
|
};
|
|
@@ -128,7 +128,7 @@ export async function captureIncomingArtifact(ctx, artifactStore) {
|
|
|
128
128
|
return store.createText({
|
|
129
129
|
text: ctx.message.text,
|
|
130
130
|
source: baseSource,
|
|
131
|
-
metadata: {}
|
|
131
|
+
metadata: { visibility: "internal", representation: "inline-message" }
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import test from "node:test";
|
|
3
|
+
import { buildPrompt, shouldIncludeArtifactReference } from "../src/transport/telegram/bot.js";
|
|
4
|
+
import { captureIncomingArtifact } from "../src/transport/telegram/media.js";
|
|
5
|
+
|
|
6
|
+
function createTextContext(text = "hello") {
|
|
7
|
+
return {
|
|
8
|
+
chat: { id: 123 },
|
|
9
|
+
from: { id: 456, username: "martin" },
|
|
10
|
+
msg: { message_id: 789 },
|
|
11
|
+
message: {
|
|
12
|
+
message_id: 789,
|
|
13
|
+
text
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
test("does not expose inline message text artifacts as prompt attachments", () => {
|
|
19
|
+
const prompt = buildPrompt({
|
|
20
|
+
ctx: createTextContext("hello"),
|
|
21
|
+
artifact: {
|
|
22
|
+
id: "artifact-1",
|
|
23
|
+
kind: "text",
|
|
24
|
+
mimeType: "text/plain",
|
|
25
|
+
text: "hello"
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
assert.match(prompt, /text: hello/);
|
|
30
|
+
assert.doesNotMatch(prompt, /artifactId: artifact-1/);
|
|
31
|
+
assert.doesNotMatch(prompt, /mimeType: text\/plain/);
|
|
32
|
+
assert.doesNotMatch(prompt, /kind: text/);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("keeps distinct artifacts visible to the prompt", () => {
|
|
36
|
+
assert.equal(
|
|
37
|
+
shouldIncludeArtifactReference({
|
|
38
|
+
artifact: {
|
|
39
|
+
id: "artifact-1",
|
|
40
|
+
kind: "document",
|
|
41
|
+
mimeType: "text/plain",
|
|
42
|
+
path: "/tmp/note.txt"
|
|
43
|
+
},
|
|
44
|
+
messageText: "see attached"
|
|
45
|
+
}),
|
|
46
|
+
true
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
assert.equal(
|
|
50
|
+
shouldIncludeArtifactReference({
|
|
51
|
+
artifact: {
|
|
52
|
+
id: "artifact-2",
|
|
53
|
+
kind: "text",
|
|
54
|
+
mimeType: "text/plain",
|
|
55
|
+
text: "different text"
|
|
56
|
+
},
|
|
57
|
+
messageText: "hello"
|
|
58
|
+
}),
|
|
59
|
+
true
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("marks incoming Telegram text artifacts as internal inline messages", async () => {
|
|
64
|
+
const calls = [];
|
|
65
|
+
const artifactStore = {
|
|
66
|
+
forChat: (chatId) => ({
|
|
67
|
+
createText: async (request) => {
|
|
68
|
+
calls.push({ chatId, ...request });
|
|
69
|
+
return { id: "artifact-1", chatId, kind: "text", mimeType: "text/plain", ...request };
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const artifact = await captureIncomingArtifact(createTextContext("hello"), artifactStore);
|
|
75
|
+
|
|
76
|
+
assert.equal(artifact.text, "hello");
|
|
77
|
+
assert.deepEqual(calls[0].metadata, {
|
|
78
|
+
visibility: "internal",
|
|
79
|
+
representation: "inline-message"
|
|
80
|
+
});
|
|
81
|
+
});
|