@chen_hu_hu/pi-qq 1.1.0 → 1.2.2
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/README-zh.md +123 -0
- package/README.md +43 -30
- package/doc/features-v1.md +50 -50
- package/doc/features-v2.md +132 -19
- package/doc/plan-v1.md +19 -19
- package/doc/plan-v2.md +100 -13
- package/index.ts +17 -9
- package/package.json +4 -1
- package/src/bot.ts +5 -3
- package/src/files.ts +162 -39
- package/src/inbound.ts +46 -9
- package/src/run-feedback.ts +5 -0
package/src/inbound.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
-
import { join } from "node:path";
|
|
3
2
|
import type { QQBot, QQBotInboundMessage } from "@tencent-connect/qqbot-nodejs";
|
|
4
3
|
import { sendReply, type ReplyChannel } from "./outbound";
|
|
5
4
|
import type { ReplyBudget } from "./reply-budget";
|
|
@@ -10,7 +9,7 @@ import {
|
|
|
10
9
|
resolveInboundImages,
|
|
11
10
|
type ImageContentLike,
|
|
12
11
|
} from "./images";
|
|
13
|
-
import { formatFilePrompt, saveInboundFiles, type SavedFile } from "./files";
|
|
12
|
+
import { formatFilePrompt, saveInboundFiles, sessionUploadDir, type SavedFile } from "./files";
|
|
14
13
|
import { log } from "./logger";
|
|
15
14
|
import { isVoiceAttachment, resolveVoiceTranscript } from "./voice";
|
|
16
15
|
|
|
@@ -40,6 +39,14 @@ export interface InboundDeps {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
export function createInboundHandler(deps: InboundDeps) {
|
|
42
|
+
// F10: files uploaded without text wait for the next text/voice instruction.
|
|
43
|
+
let pendingFiles: SavedFile[] = [];
|
|
44
|
+
const takePendingFiles = (): SavedFile[] => {
|
|
45
|
+
const files = pendingFiles;
|
|
46
|
+
pendingFiles = [];
|
|
47
|
+
return files;
|
|
48
|
+
};
|
|
49
|
+
|
|
43
50
|
return async (bot: QQBot, msg: QQBotInboundMessage): Promise<void> => {
|
|
44
51
|
log.debug("inbound", "message received", {
|
|
45
52
|
kind: msg.kind,
|
|
@@ -89,7 +96,12 @@ export function createInboundHandler(deps: InboundDeps) {
|
|
|
89
96
|
|
|
90
97
|
const text = (msg.content ?? "").trim();
|
|
91
98
|
if (text.startsWith("/")) {
|
|
92
|
-
|
|
99
|
+
const command = text.split(/\s+/)[0];
|
|
100
|
+
log.info("inbound", "QQ command", { command });
|
|
101
|
+
if (command === "/new" && deps.ctx.isIdle() && pendingFiles.length > 0) {
|
|
102
|
+
log.info("inbound", "cleared pending files for /new", { count: pendingFiles.length });
|
|
103
|
+
pendingFiles = [];
|
|
104
|
+
}
|
|
93
105
|
await handleCommand(text, reply, deps);
|
|
94
106
|
return;
|
|
95
107
|
}
|
|
@@ -116,9 +128,15 @@ export function createInboundHandler(deps: InboundDeps) {
|
|
|
116
128
|
return;
|
|
117
129
|
}
|
|
118
130
|
log.debug("inbound", "voice transcript", { messageId: msg.messageId, transcript });
|
|
131
|
+
const pending = takePendingFiles();
|
|
132
|
+
const promptText = formatFilePrompt(pending, transcript);
|
|
119
133
|
deps.markQQTrigger(msg.senderId, msg.messageId);
|
|
120
|
-
deps.pi.sendUserMessage(
|
|
121
|
-
log.info("inbound", "voice sent to pi", {
|
|
134
|
+
deps.pi.sendUserMessage(promptText, { deliverAs: deps.getDeliverAs() });
|
|
135
|
+
log.info("inbound", "voice sent to pi", {
|
|
136
|
+
messageId: msg.messageId,
|
|
137
|
+
asrLength: transcript.length,
|
|
138
|
+
pendingFiles: pending.length,
|
|
139
|
+
});
|
|
122
140
|
return;
|
|
123
141
|
}
|
|
124
142
|
|
|
@@ -145,10 +163,15 @@ export function createInboundHandler(deps: InboundDeps) {
|
|
|
145
163
|
|
|
146
164
|
let files: SavedFile[] = [];
|
|
147
165
|
if (fileAttachments.length > 0) {
|
|
166
|
+
const uploadDir = sessionUploadDir(deps.ctx.cwd, deps.ctx.sessionManager.getSessionId());
|
|
167
|
+
log.debug("inbound", "saving files", {
|
|
168
|
+
messageId: msg.messageId,
|
|
169
|
+
count: fileAttachments.length,
|
|
170
|
+
uploadDir,
|
|
171
|
+
});
|
|
148
172
|
const result = await saveFiles(fileAttachments, {
|
|
149
173
|
maxSize: deps.getFileMaxSize(),
|
|
150
|
-
|
|
151
|
-
dirKey: msg.messageId,
|
|
174
|
+
uploadDir,
|
|
152
175
|
});
|
|
153
176
|
files = result.files;
|
|
154
177
|
failures.push(...result.failures);
|
|
@@ -170,15 +193,29 @@ export function createInboundHandler(deps: InboundDeps) {
|
|
|
170
193
|
return;
|
|
171
194
|
}
|
|
172
195
|
|
|
196
|
+
// F10: a file-only message waits for the next text/voice instruction.
|
|
197
|
+
if (!text && images.length === 0 && files.length > 0) {
|
|
198
|
+
pendingFiles.push(...files);
|
|
199
|
+
log.info("inbound", "files pending for instruction", {
|
|
200
|
+
messageId: msg.messageId,
|
|
201
|
+
count: files.length,
|
|
202
|
+
pendingCount: pendingFiles.length,
|
|
203
|
+
});
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
173
207
|
// F7: mark a QQ-triggered run; do not send a start confirmation.
|
|
174
208
|
deps.markQQTrigger(msg.senderId, msg.messageId);
|
|
175
|
-
const
|
|
209
|
+
const pending = text ? takePendingFiles() : [];
|
|
210
|
+
const promptFiles = [...pending, ...files];
|
|
211
|
+
const promptText = formatFilePrompt(promptFiles, text);
|
|
176
212
|
deps.pi.sendUserMessage(buildImageMessageContent(promptText, images), { deliverAs: deps.getDeliverAs() });
|
|
177
213
|
log.info("inbound", "sent to pi", {
|
|
178
214
|
messageId: msg.messageId,
|
|
179
215
|
textLength: text.length,
|
|
180
216
|
images: images.length,
|
|
181
|
-
files:
|
|
217
|
+
files: promptFiles.length,
|
|
218
|
+
pendingFiles: pending.length,
|
|
182
219
|
deliverAs: deps.getDeliverAs(),
|
|
183
220
|
});
|
|
184
221
|
};
|
package/src/run-feedback.ts
CHANGED
|
@@ -116,6 +116,11 @@ export class RunFeedback {
|
|
|
116
116
|
this.pending = { openid, msgId, at: Date.now() };
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/** Whether a QQ-triggered run is active. Local pi runs have no RunFeedback state. */
|
|
120
|
+
isQQRunActive(): boolean {
|
|
121
|
+
return this.run !== null;
|
|
122
|
+
}
|
|
123
|
+
|
|
119
124
|
onAgentStart(): void {
|
|
120
125
|
const pending = this.pending;
|
|
121
126
|
this.pending = null;
|