@krtclcdy/tersio 1.0.4 → 2.0.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.
@@ -1,24 +0,0 @@
1
- const REWARD_KEY = /(?<![A-Za-z0-9_-])AMANAI-GACHA-[A-Za-z0-9]+-[A-Za-z0-9]+(?![A-Za-z0-9_-])/;
2
- const NOTIFICATION = "Amanai reward key detected in the final response. Redeem it manually in the Amanai billing dashboard.";
3
- export default function amanaiRewardExtension(pi) {
4
- pi.on("agent_end", (event, ctx) => {
5
- if (event.willContinue)
6
- return;
7
- const messages = Array.isArray(event.messages) ? event.messages : [];
8
- let message;
9
- for (let index = messages.length - 1; index >= 0; index -= 1) {
10
- if (messages[index]?.role === "assistant") {
11
- message = messages[index];
12
- break;
13
- }
14
- }
15
- if (!message || message.stopReason !== "stop" || !Array.isArray(message.content))
16
- return;
17
- for (const block of message.content) {
18
- if (block?.type === "text" && typeof block.text === "string" && REWARD_KEY.test(block.text)) {
19
- ctx?.ui?.notify?.(NOTIFICATION, "info");
20
- return;
21
- }
22
- }
23
- });
24
- }
@@ -1,32 +0,0 @@
1
- const REWARD_KEY = /(?<![A-Za-z0-9_-])AMANAI-GACHA-[A-Za-z0-9]+-[A-Za-z0-9]+(?![A-Za-z0-9_-])/;
2
- const NOTIFICATION = "Amanai reward key detected in the final response. Redeem it manually in the Amanai billing dashboard.";
3
- export default function amanaiRewardExtension(pi) {
4
- let candidate = false;
5
- pi.on("agent_start", () => {
6
- candidate = false;
7
- });
8
- pi.on("agent_end", (event) => {
9
- candidate = false;
10
- const messages = Array.isArray(event?.messages) ? event.messages : [];
11
- let message;
12
- for (let index = messages.length - 1; index >= 0; index -= 1) {
13
- if (messages[index]?.role === "assistant") {
14
- message = messages[index];
15
- break;
16
- }
17
- }
18
- if (message?.stopReason !== "stop" || !Array.isArray(message.content))
19
- return;
20
- candidate = message.content.some((block) => block?.type === "text" && typeof block.text === "string" && REWARD_KEY.test(block.text));
21
- });
22
- pi.on("agent_settled", (_event, ctx) => {
23
- const c = ctx;
24
- try {
25
- if (candidate && c?.hasUI && c.ui)
26
- c.ui.notify(NOTIFICATION, "info");
27
- }
28
- finally {
29
- candidate = false;
30
- }
31
- });
32
- }