@dmsdc-ai/aigentry-telepty 0.1.22 → 0.1.24
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/cli.js +7 -2
- package/daemon.js +32 -12
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -978,6 +978,11 @@ async function main() {
|
|
|
978
978
|
args.splice(replyToIndex, 2);
|
|
979
979
|
}
|
|
980
980
|
|
|
981
|
+
// Extract --reply-expected flag
|
|
982
|
+
const replyExpectedIndex = args.indexOf('--reply-expected');
|
|
983
|
+
const replyExpected = replyExpectedIndex !== -1;
|
|
984
|
+
if (replyExpected) args.splice(replyExpectedIndex, 1);
|
|
985
|
+
|
|
981
986
|
const sessionId = args[1]; const prompt = args.slice(2).join(' ');
|
|
982
987
|
if (!sessionId || !prompt) { console.error('❌ Usage: telepty inject [--no-enter] [--from <id>] [--reply-to <id>] <session_id> "<prompt text>"'); process.exit(1); }
|
|
983
988
|
try {
|
|
@@ -990,6 +995,7 @@ async function main() {
|
|
|
990
995
|
const body = { prompt, no_enter: noEnter };
|
|
991
996
|
if (fromId) body.from = fromId;
|
|
992
997
|
if (replyTo) body.reply_to = replyTo;
|
|
998
|
+
if (replyExpected) body.reply_expected = true;
|
|
993
999
|
|
|
994
1000
|
const res = await fetchWithAuth(`http://${target.host}:${PORT}/api/sessions/${encodeURIComponent(target.id)}/inject`, {
|
|
995
1001
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body)
|
|
@@ -1015,8 +1021,7 @@ async function main() {
|
|
|
1015
1021
|
if (!replyTo) { console.error(`❌ No pending reply-to found for session '${mySessionId}'`); process.exit(1); }
|
|
1016
1022
|
const target = await resolveSessionTarget(replyTo);
|
|
1017
1023
|
if (!target) { console.error(`❌ Session '${replyTo}' was not found on any discovered host.`); process.exit(1); }
|
|
1018
|
-
const
|
|
1019
|
-
const body = { prompt: fullPrompt, from: mySessionId, reply_to: mySessionId };
|
|
1024
|
+
const body = { prompt: replyText, from: mySessionId, reply_to: mySessionId };
|
|
1020
1025
|
const res = await fetchWithAuth(`http://${target.host}:${PORT}/api/sessions/${encodeURIComponent(target.id)}/inject`, {
|
|
1021
1026
|
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body)
|
|
1022
1027
|
});
|
package/daemon.js
CHANGED
|
@@ -530,10 +530,20 @@ app.post('/api/sessions/:id/inject', (req, res) => {
|
|
|
530
530
|
if (!resolvedId) return res.status(404).json({ error: 'Session not found', requested: requestedId });
|
|
531
531
|
const session = sessions[resolvedId];
|
|
532
532
|
const id = resolvedId;
|
|
533
|
-
const { prompt, no_enter, auto_submit,
|
|
533
|
+
const { prompt, no_enter, auto_submit, thread_id, reply_expected } = req.body;
|
|
534
|
+
let { from, reply_to } = req.body;
|
|
534
535
|
if (!prompt) return res.status(400).json({ error: 'prompt is required' });
|
|
536
|
+
// reply_to defaults to from when omitted
|
|
537
|
+
if (from && !reply_to) reply_to = from;
|
|
535
538
|
if (from) session.lastInjectFrom = from;
|
|
536
539
|
if (reply_to) session.lastInjectReplyTo = reply_to;
|
|
540
|
+
if (thread_id) session.lastThreadId = thread_id;
|
|
541
|
+
|
|
542
|
+
// Auto-prepend [from:] [reply-to:] header if from is set and not already in prompt
|
|
543
|
+
let finalPrompt = prompt;
|
|
544
|
+
if (from && !prompt.startsWith('[from:')) {
|
|
545
|
+
finalPrompt = `[from: ${from}] [reply-to: ${reply_to}] ${prompt}`;
|
|
546
|
+
}
|
|
537
547
|
const inject_id = crypto.randomUUID();
|
|
538
548
|
try {
|
|
539
549
|
// Always inject text WITHOUT \r first, then send \r separately after delay
|
|
@@ -551,18 +561,26 @@ app.post('/api/sessions/:id/inject', (req, res) => {
|
|
|
551
561
|
}
|
|
552
562
|
}
|
|
553
563
|
|
|
554
|
-
if (!writeToSession(prompt)) {
|
|
555
|
-
return res.status(503).json({ error: 'Wrap process is not connected' });
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
// Send \r separately after 300ms delay — works for ALL CLIs
|
|
559
564
|
let submitResult = null;
|
|
560
|
-
if (!no_enter) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
}
|
|
565
|
-
submitResult = {
|
|
565
|
+
if (!no_enter && session.type === 'wrapped') {
|
|
566
|
+
// Wrapped sessions: send text+\r in single message to bypass allow bridge prompt-ready gate
|
|
567
|
+
if (!writeToSession(finalPrompt + '\r')) {
|
|
568
|
+
return res.status(503).json({ error: 'Wrap process is not connected' });
|
|
569
|
+
}
|
|
570
|
+
submitResult = { strategy: 'combined_cr' };
|
|
571
|
+
console.log(`[INJECT+SUBMIT] Combined \\r for ${id}`);
|
|
572
|
+
} else {
|
|
573
|
+
if (!writeToSession(finalPrompt)) {
|
|
574
|
+
return res.status(503).json({ error: 'Wrap process is not connected' });
|
|
575
|
+
}
|
|
576
|
+
// Spawned sessions: send \r separately after delay (proven split_cr strategy)
|
|
577
|
+
if (!no_enter) {
|
|
578
|
+
setTimeout(() => {
|
|
579
|
+
const ok = writeToSession('\r');
|
|
580
|
+
console.log(`[INJECT+SUBMIT] Split \\r for ${id}: ${ok ? 'success' : 'failed'}`);
|
|
581
|
+
}, 300);
|
|
582
|
+
submitResult = { deferred: true, strategy: 'split_cr' };
|
|
583
|
+
}
|
|
566
584
|
}
|
|
567
585
|
|
|
568
586
|
console.log(`[INJECT] Wrote to session ${id} (inject_id: ${inject_id})`);
|
|
@@ -575,6 +593,8 @@ app.post('/api/sessions/:id/inject', (req, res) => {
|
|
|
575
593
|
content: prompt,
|
|
576
594
|
from: from || null,
|
|
577
595
|
reply_to: reply_to || null,
|
|
596
|
+
thread_id: thread_id || null,
|
|
597
|
+
reply_expected: !!reply_expected,
|
|
578
598
|
timestamp: new Date().toISOString()
|
|
579
599
|
});
|
|
580
600
|
busClients.forEach(client => {
|