@poncho-ai/messaging 0.4.0 → 0.5.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/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +13 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +41 -20
- package/package.json +2 -2
- package/src/bridge.ts +53 -23
- package/src/types.ts +3 -0
- package/.turbo/turbo-test.log +0 -29
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @poncho-ai/messaging@0.
|
|
2
|
+
> @poncho-ai/messaging@0.5.1 build /home/runner/work/poncho-ai/poncho-ai/packages/messaging
|
|
3
3
|
> tsup src/index.ts --format esm --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
[34mCLI[39m tsup v8.5.1
|
|
8
8
|
[34mCLI[39m Target: es2022
|
|
9
9
|
[34mESM[39m Build start
|
|
10
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
11
|
-
[32mESM[39m ⚡️ Build success in
|
|
10
|
+
[32mESM[39m [1mdist/index.js [22m[32m45.94 KB[39m
|
|
11
|
+
[32mESM[39m ⚡️ Build success in 66ms
|
|
12
12
|
[34mDTS[39m Build start
|
|
13
|
-
[32mDTS[39m ⚡️ Build success in
|
|
14
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m10.
|
|
13
|
+
[32mDTS[39m ⚡️ Build success in 5216ms
|
|
14
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m10.13 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @poncho-ai/messaging
|
|
2
2
|
|
|
3
|
+
## 0.5.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`6f0abfd`](https://github.com/cesr/poncho-ai/commit/6f0abfd9f729b545cf293741ee813f705910aaf3)]:
|
|
8
|
+
- @poncho-ai/sdk@1.5.0
|
|
9
|
+
|
|
10
|
+
## 0.5.0
|
|
11
|
+
|
|
12
|
+
### Minor Changes
|
|
13
|
+
|
|
14
|
+
- [`8ef9316`](https://github.com/cesr/poncho-ai/commit/8ef93165084b4df581e39a1581b1ead64b7b3f42) Thanks [@cesr](https://github.com/cesr)! - Add auto-continuation support for messaging adapters (Telegram, Slack, Resend) on serverless platforms. When `PONCHO_MAX_DURATION` is set, agent runs that hit the soft deadline now automatically resume with "Continue" messages, matching the web UI and client SDK behavior.
|
|
15
|
+
|
|
3
16
|
## 0.4.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ var AgentBridge = class {
|
|
|
33
33
|
await this.adapter.initialize();
|
|
34
34
|
}
|
|
35
35
|
async handleMessage(message) {
|
|
36
|
+
const MAX_CONTINUATIONS = 10;
|
|
36
37
|
let cleanup;
|
|
37
38
|
this.adapter.resetRequestState?.();
|
|
38
39
|
try {
|
|
@@ -46,33 +47,53 @@ var AgentBridge = class {
|
|
|
46
47
|
const titleParts = [platformTag, senderLabel];
|
|
47
48
|
if (message.subject) titleParts.push(message.subject);
|
|
48
49
|
const title = titleParts.join(" ") || `${message.platform} thread`;
|
|
49
|
-
const conversation = await this.runner.getOrCreateConversation(
|
|
50
|
-
conversationId,
|
|
51
|
-
{
|
|
52
|
-
platform: message.platform,
|
|
53
|
-
ownerId: this.ownerIdOverride ?? message.sender.id,
|
|
54
|
-
title
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
50
|
const senderLine = message.sender.name ? `From: ${message.sender.name} <${message.sender.id}>` : `From: ${message.sender.id}`;
|
|
58
51
|
const subjectLine = message.subject ? `Subject: ${message.subject}` : "";
|
|
59
52
|
const header = [senderLine, subjectLine].filter(Boolean).join("\n");
|
|
60
|
-
|
|
53
|
+
let currentTask = `${header}
|
|
61
54
|
|
|
62
55
|
${message.text}`;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
let currentFiles = message.files;
|
|
57
|
+
let accumulatedResponse = "";
|
|
58
|
+
let accumulatedFiles = [];
|
|
59
|
+
let totalSteps = 0;
|
|
60
|
+
let stepBudget = 0;
|
|
61
|
+
let continuationCount = 0;
|
|
62
|
+
while (true) {
|
|
63
|
+
const conversation = await this.runner.getOrCreateConversation(
|
|
64
|
+
conversationId,
|
|
65
|
+
{
|
|
66
|
+
platform: message.platform,
|
|
67
|
+
ownerId: this.ownerIdOverride ?? message.sender.id,
|
|
68
|
+
title
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
const result = await this.runner.run(conversationId, {
|
|
72
|
+
task: currentTask,
|
|
73
|
+
messages: conversation.messages,
|
|
74
|
+
files: currentFiles,
|
|
75
|
+
metadata: {
|
|
76
|
+
platform: message.platform,
|
|
77
|
+
sender: message.sender,
|
|
78
|
+
threadId: message.threadRef.platformThreadId
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
accumulatedResponse += result.response;
|
|
82
|
+
if (result.files) accumulatedFiles.push(...result.files);
|
|
83
|
+
totalSteps += result.steps ?? 0;
|
|
84
|
+
if (typeof result.maxSteps === "number") stepBudget = result.maxSteps;
|
|
85
|
+
if (result.continuation && continuationCount < MAX_CONTINUATIONS && (stepBudget <= 0 || totalSteps < stepBudget)) {
|
|
86
|
+
continuationCount++;
|
|
87
|
+
console.log(`[agent-bridge] continuation ${continuationCount}/${MAX_CONTINUATIONS} for ${conversationId}`);
|
|
88
|
+
currentTask = "Continue";
|
|
89
|
+
currentFiles = void 0;
|
|
90
|
+
continue;
|
|
71
91
|
}
|
|
72
|
-
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
73
94
|
if (this.adapter.autoReply) {
|
|
74
|
-
await this.adapter.sendReply(message.threadRef,
|
|
75
|
-
files:
|
|
95
|
+
await this.adapter.sendReply(message.threadRef, accumulatedResponse, {
|
|
96
|
+
files: accumulatedFiles.length > 0 ? accumulatedFiles : void 0
|
|
76
97
|
});
|
|
77
98
|
} else if (!this.adapter.hasSentInCurrentRequest) {
|
|
78
99
|
console.warn("[agent-bridge] tool mode completed without send_email being called; no reply sent");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@poncho-ai/messaging",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Messaging platform adapters for Poncho agents (Slack, Telegram, etc.)",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@poncho-ai/sdk": "1.
|
|
23
|
+
"@poncho-ai/sdk": "1.5.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"resend": ">=4.0.0"
|
package/src/bridge.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import type {
|
|
3
3
|
AgentBridgeOptions,
|
|
4
|
+
FileAttachment,
|
|
4
5
|
IncomingMessage,
|
|
5
6
|
MessagingAdapter,
|
|
6
7
|
AgentRunner,
|
|
@@ -53,6 +54,7 @@ export class AgentBridge {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
private async handleMessage(message: IncomingMessage): Promise<void> {
|
|
57
|
+
const MAX_CONTINUATIONS = 10;
|
|
56
58
|
let cleanup: (() => Promise<void>) | undefined;
|
|
57
59
|
|
|
58
60
|
this.adapter.resetRequestState?.();
|
|
@@ -71,36 +73,64 @@ export class AgentBridge {
|
|
|
71
73
|
if (message.subject) titleParts.push(message.subject);
|
|
72
74
|
const title = titleParts.join(" ") || `${message.platform} thread`;
|
|
73
75
|
|
|
74
|
-
const conversation = await this.runner.getOrCreateConversation(
|
|
75
|
-
conversationId,
|
|
76
|
-
{
|
|
77
|
-
platform: message.platform,
|
|
78
|
-
ownerId: this.ownerIdOverride ?? message.sender.id,
|
|
79
|
-
title,
|
|
80
|
-
},
|
|
81
|
-
);
|
|
82
|
-
|
|
83
76
|
const senderLine = message.sender.name
|
|
84
77
|
? `From: ${message.sender.name} <${message.sender.id}>`
|
|
85
78
|
: `From: ${message.sender.id}`;
|
|
86
79
|
const subjectLine = message.subject ? `Subject: ${message.subject}` : "";
|
|
87
80
|
const header = [senderLine, subjectLine].filter(Boolean).join("\n");
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
|
|
82
|
+
let currentTask = `${header}\n\n${message.text}`;
|
|
83
|
+
let currentFiles = message.files;
|
|
84
|
+
let accumulatedResponse = "";
|
|
85
|
+
let accumulatedFiles: FileAttachment[] = [];
|
|
86
|
+
let totalSteps = 0;
|
|
87
|
+
let stepBudget = 0;
|
|
88
|
+
let continuationCount = 0;
|
|
89
|
+
|
|
90
|
+
while (true) {
|
|
91
|
+
const conversation = await this.runner.getOrCreateConversation(
|
|
92
|
+
conversationId,
|
|
93
|
+
{
|
|
94
|
+
platform: message.platform,
|
|
95
|
+
ownerId: this.ownerIdOverride ?? message.sender.id,
|
|
96
|
+
title,
|
|
97
|
+
},
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const result = await this.runner.run(conversationId, {
|
|
101
|
+
task: currentTask,
|
|
102
|
+
messages: conversation.messages,
|
|
103
|
+
files: currentFiles,
|
|
104
|
+
metadata: {
|
|
105
|
+
platform: message.platform,
|
|
106
|
+
sender: message.sender,
|
|
107
|
+
threadId: message.threadRef.platformThreadId,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
accumulatedResponse += result.response;
|
|
112
|
+
if (result.files) accumulatedFiles.push(...result.files);
|
|
113
|
+
totalSteps += result.steps ?? 0;
|
|
114
|
+
if (typeof result.maxSteps === "number") stepBudget = result.maxSteps;
|
|
115
|
+
|
|
116
|
+
if (
|
|
117
|
+
result.continuation &&
|
|
118
|
+
continuationCount < MAX_CONTINUATIONS &&
|
|
119
|
+
(stepBudget <= 0 || totalSteps < stepBudget)
|
|
120
|
+
) {
|
|
121
|
+
continuationCount++;
|
|
122
|
+
console.log(`[agent-bridge] continuation ${continuationCount}/${MAX_CONTINUATIONS} for ${conversationId}`);
|
|
123
|
+
currentTask = "Continue";
|
|
124
|
+
currentFiles = undefined;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
100
130
|
|
|
101
131
|
if (this.adapter.autoReply) {
|
|
102
|
-
await this.adapter.sendReply(message.threadRef,
|
|
103
|
-
files:
|
|
132
|
+
await this.adapter.sendReply(message.threadRef, accumulatedResponse, {
|
|
133
|
+
files: accumulatedFiles.length > 0 ? accumulatedFiles : undefined,
|
|
104
134
|
});
|
|
105
135
|
} else if (!this.adapter.hasSentInCurrentRequest) {
|
|
106
136
|
console.warn("[agent-bridge] tool mode completed without send_email being called; no reply sent");
|
package/src/types.ts
CHANGED
package/.turbo/turbo-test.log
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @poncho-ai/messaging@0.2.4 test /Users/cesar/Dev/latitude/poncho-ai/packages/messaging
|
|
3
|
-
> vitest
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
[7m[1m[36m RUN [39m[22m[27m [36mv1.6.1[39m [90m/Users/cesar/Dev/latitude/poncho-ai/packages/messaging[39m
|
|
7
|
-
|
|
8
|
-
[90mstderr[2m | test/bridge.test.ts[2m > [22m[2mAgentBridge[2m > [22m[2mposts an error message and cleans up on runner failure[22m[39m
|
|
9
|
-
[agent-bridge] handleMessage error: Model overloaded
|
|
10
|
-
|
|
11
|
-
[90mstderr[2m | test/bridge.test.ts[2m > [22m[2mAgentBridge[2m > [22m[2mskips sendReply when autoReply is false[22m[39m
|
|
12
|
-
[agent-bridge] tool mode completed without send_email being called; no reply sent
|
|
13
|
-
|
|
14
|
-
[90mstderr[2m | test/bridge.test.ts[2m > [22m[2mAgentBridge[2m > [22m[2msuppresses error reply when hasSentInCurrentRequest is true[22m[39m
|
|
15
|
-
[agent-bridge] handleMessage error: Oops
|
|
16
|
-
|
|
17
|
-
[90mstderr[2m | test/bridge.test.ts[2m > [22m[2mAgentBridge[2m > [22m[2mcalls resetRequestState before handling each message[22m[39m
|
|
18
|
-
[agent-bridge] tool mode completed without send_email being called; no reply sent
|
|
19
|
-
|
|
20
|
-
[32m✓[39m test/bridge.test.ts [2m ([22m[2m15 tests[22m[2m)[22m[90m 7[2mms[22m[39m
|
|
21
|
-
[32m✓[39m test/adapters/email-utils.test.ts [2m ([22m[2m44 tests[22m[2m)[22m[90m 13[2mms[22m[39m
|
|
22
|
-
[32m✓[39m test/adapters/resend.test.ts [2m ([22m[2m13 tests[22m[2m)[22m[90m 7[2mms[22m[39m
|
|
23
|
-
[32m✓[39m test/adapters/slack.test.ts [2m ([22m[2m17 tests[22m[2m)[22m[90m 61[2mms[22m[39m
|
|
24
|
-
|
|
25
|
-
[2m Test Files [22m [1m[32m4 passed[39m[22m[90m (4)[39m
|
|
26
|
-
[2m Tests [22m [1m[32m89 passed[39m[22m[90m (89)[39m
|
|
27
|
-
[2m Start at [22m 17:47:42
|
|
28
|
-
[2m Duration [22m 442ms[2m (transform 223ms, setup 0ms, collect 336ms, tests 88ms, environment 0ms, prepare 304ms)[22m
|
|
29
|
-
|