@pmate/cli 0.25.0 → 0.25.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/dist/index.d.ts +1 -0
- package/dist/index.js +104 -29
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -16179,7 +16179,11 @@ var CollectCommandHandler = class {
|
|
|
16179
16179
|
if (!thread) {
|
|
16180
16180
|
throw new Error(`Thread not found: ${args.thread}`);
|
|
16181
16181
|
}
|
|
16182
|
-
await this.sendReplyViaConversation(targetPage, thread, args.text);
|
|
16182
|
+
const result = await this.sendReplyViaConversation(targetPage, thread, args.text, args.dryRun);
|
|
16183
|
+
if (args.dryRun) {
|
|
16184
|
+
ui.plain(JSON.stringify({ source: target.sourceKey, thread: thread.name, ...result }, null, 2));
|
|
16185
|
+
return;
|
|
16186
|
+
}
|
|
16183
16187
|
ui.success("im1 reply sent", { source: target.sourceKey, thread: thread.name });
|
|
16184
16188
|
} catch (error) {
|
|
16185
16189
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -16412,14 +16416,15 @@ var CollectCommandHandler = class {
|
|
|
16412
16416
|
await session.detach().catch(() => void 0);
|
|
16413
16417
|
}
|
|
16414
16418
|
}
|
|
16415
|
-
async sendReplyViaConversation(page, thread, text) {
|
|
16419
|
+
async sendReplyViaConversation(page, thread, text, dryRun) {
|
|
16416
16420
|
const result = await this.evaluateInPage(
|
|
16417
16421
|
page,
|
|
16418
|
-
buildSendMessageExpr(thread.conversationId, text)
|
|
16422
|
+
buildSendMessageExpr(thread.conversationId, text, dryRun)
|
|
16419
16423
|
);
|
|
16420
16424
|
if (!result?.ok) {
|
|
16421
16425
|
throw new Error(result?.reason || "Send failed");
|
|
16422
16426
|
}
|
|
16427
|
+
return result;
|
|
16423
16428
|
}
|
|
16424
16429
|
};
|
|
16425
16430
|
async function archiveMessageImages(rootDir, sourceKey, threadKey, messages2) {
|
|
@@ -16674,7 +16679,7 @@ function buildGetMessagesByConversationExpr(conversationId, limit) {
|
|
|
16674
16679
|
}
|
|
16675
16680
|
})()`;
|
|
16676
16681
|
}
|
|
16677
|
-
function buildSendMessageExpr(conversationId, message) {
|
|
16682
|
+
function buildSendMessageExpr(conversationId, message, dryRun = false) {
|
|
16678
16683
|
const escapedConversationId = escapeForJs(conversationId);
|
|
16679
16684
|
const escapedMessage = escapeForJs(message);
|
|
16680
16685
|
return `(async function() {
|
|
@@ -16696,17 +16701,25 @@ function buildSendMessageExpr(conversationId, message) {
|
|
|
16696
16701
|
.replace(/\\u200B/g, '')
|
|
16697
16702
|
.trim();
|
|
16698
16703
|
}
|
|
16699
|
-
function addLookup(lookup, name, id) {
|
|
16704
|
+
function addLookup(lookup, name, id, label) {
|
|
16700
16705
|
var normalized = normalizeMentionName(name);
|
|
16701
16706
|
if (!normalized || !id || lookup[normalized]) return;
|
|
16702
|
-
lookup[normalized] = id;
|
|
16707
|
+
lookup[normalized] = { uid: id, label: normalizeMentionName(label || name) };
|
|
16703
16708
|
}
|
|
16704
16709
|
function addMentionAliases(lookup, name, id) {
|
|
16705
16710
|
var normalized = normalizeMentionName(name);
|
|
16706
|
-
addLookup(lookup, normalized, id);
|
|
16707
|
-
addLookup(lookup, normalized.replace(/\\s*\\([^)]*\\)\\s*$/g, ''), id);
|
|
16708
|
-
addLookup(lookup, normalized.replace(/\\s*\\[[^\\]]*\\]\\s*$/g, ''), id);
|
|
16709
|
-
addLookup(lookup, normalized.replace(/\\s*[\uFF08][^\uFF09]*[\uFF09]\\s*$/g, ''), id);
|
|
16711
|
+
addLookup(lookup, normalized, id, normalized);
|
|
16712
|
+
addLookup(lookup, normalized.replace(/\\s*\\([^)]*\\)\\s*$/g, ''), id, normalized);
|
|
16713
|
+
addLookup(lookup, normalized.replace(/\\s*\\[[^\\]]*\\]\\s*$/g, ''), id, normalized);
|
|
16714
|
+
addLookup(lookup, normalized.replace(/\\s*[\uFF08][^\uFF09]*[\uFF09]\\s*$/g, ''), id, normalized);
|
|
16715
|
+
}
|
|
16716
|
+
function addContactToLookup(lookup, contact) {
|
|
16717
|
+
if (!contact) return;
|
|
16718
|
+
var id = normalizeMentionName(contact && contact.get ? contact.get('id') : contact && contact.id);
|
|
16719
|
+
if (!id) return;
|
|
16720
|
+
addMentionAliases(lookup, contact && contact.get ? contact.get('name') : contact && contact.name, id);
|
|
16721
|
+
addMentionAliases(lookup, contact && contact.get ? contact.get('profileName') : contact && contact.profileName, id);
|
|
16722
|
+
addMentionAliases(lookup, contact && contact.get ? contact.get('title') : contact && contact.title, id);
|
|
16710
16723
|
}
|
|
16711
16724
|
function buildMentionLookup() {
|
|
16712
16725
|
var lookup = {};
|
|
@@ -16716,12 +16729,21 @@ function buildSendMessageExpr(conversationId, message) {
|
|
|
16716
16729
|
all = privates.models || privates || [];
|
|
16717
16730
|
}
|
|
16718
16731
|
for (var i = 0; i < all.length; i++) {
|
|
16719
|
-
|
|
16720
|
-
|
|
16721
|
-
|
|
16722
|
-
|
|
16723
|
-
|
|
16724
|
-
|
|
16732
|
+
addContactToLookup(lookup, all[i]);
|
|
16733
|
+
}
|
|
16734
|
+
var memberIds = [];
|
|
16735
|
+
var membersV2 = conversation && conversation.get ? (conversation.get('membersV2') || []) : [];
|
|
16736
|
+
var members = conversation && conversation.get ? (conversation.get('members') || []) : [];
|
|
16737
|
+
for (var j = 0; j < membersV2.length; j++) {
|
|
16738
|
+
memberIds.push(membersV2[j].id || membersV2[j]);
|
|
16739
|
+
addMentionAliases(lookup, membersV2[j].displayName, membersV2[j].id);
|
|
16740
|
+
}
|
|
16741
|
+
for (var k = 0; k < members.length; k++) {
|
|
16742
|
+
memberIds.push(members[k]);
|
|
16743
|
+
}
|
|
16744
|
+
for (var m = 0; m < memberIds.length; m++) {
|
|
16745
|
+
var memberContact = controller.get(memberIds[m]);
|
|
16746
|
+
if (memberContact) addContactToLookup(lookup, memberContact);
|
|
16725
16747
|
}
|
|
16726
16748
|
return lookup;
|
|
16727
16749
|
}
|
|
@@ -16749,8 +16771,9 @@ function buildSendMessageExpr(conversationId, message) {
|
|
|
16749
16771
|
}
|
|
16750
16772
|
function resolveFuzzyMention(query, lookup) {
|
|
16751
16773
|
var queryKey = normalizeMentionKey(query);
|
|
16752
|
-
if (!queryKey) return null;
|
|
16774
|
+
if (!queryKey) return { uid: null, reason: 'empty-query', candidates: [] };
|
|
16753
16775
|
var scoresByUid = {};
|
|
16776
|
+
var labelsByUid = {};
|
|
16754
16777
|
var aliases = Object.keys(lookup);
|
|
16755
16778
|
for (var i = 0; i < aliases.length; i++) {
|
|
16756
16779
|
var alias = aliases[i];
|
|
@@ -16763,15 +16786,20 @@ function buildSendMessageExpr(conversationId, message) {
|
|
|
16763
16786
|
else if (aliasKey.indexOf(queryKey) !== -1) score = 60;
|
|
16764
16787
|
else if (queryKey.indexOf(aliasKey) !== -1) score = 40;
|
|
16765
16788
|
if (score === 0) continue;
|
|
16766
|
-
var
|
|
16789
|
+
var entry = lookup[alias];
|
|
16790
|
+
var uid = entry.uid;
|
|
16767
16791
|
if (!scoresByUid[uid] || score > scoresByUid[uid]) {
|
|
16768
16792
|
scoresByUid[uid] = score;
|
|
16793
|
+
labelsByUid[uid] = entry.label || alias;
|
|
16769
16794
|
}
|
|
16770
16795
|
}
|
|
16771
16796
|
var bestUid = null;
|
|
16772
16797
|
var bestScore = 0;
|
|
16773
16798
|
var bestCount = 0;
|
|
16774
16799
|
var uids = Object.keys(scoresByUid);
|
|
16800
|
+
var candidates = uids.map(function(uid) {
|
|
16801
|
+
return { uid: uid, name: labelsByUid[uid], score: scoresByUid[uid] };
|
|
16802
|
+
}).sort(function(a, b) { return b.score - a.score || String(a.name || '').localeCompare(String(b.name || '')); });
|
|
16775
16803
|
for (var j = 0; j < uids.length; j++) {
|
|
16776
16804
|
var uidScore = scoresByUid[uids[j]];
|
|
16777
16805
|
if (uidScore > bestScore) {
|
|
@@ -16782,12 +16810,15 @@ function buildSendMessageExpr(conversationId, message) {
|
|
|
16782
16810
|
bestCount += 1;
|
|
16783
16811
|
}
|
|
16784
16812
|
}
|
|
16785
|
-
|
|
16813
|
+
if (!bestUid) return { uid: null, reason: 'no-match', candidates: candidates.slice(0, 5) };
|
|
16814
|
+
if (bestCount !== 1) return { uid: null, reason: 'ambiguous', candidates: candidates.slice(0, 5) };
|
|
16815
|
+
return { uid: bestUid, label: labelsByUid[bestUid], reason: 'matched', candidates: candidates.slice(0, 5) };
|
|
16786
16816
|
}
|
|
16787
16817
|
function extractMentions(text) {
|
|
16788
16818
|
var lookup = buildMentionLookup();
|
|
16789
16819
|
var names = Object.keys(lookup).sort(function(a, b) { return b.length - a.length; });
|
|
16790
|
-
var
|
|
16820
|
+
var replacements = [];
|
|
16821
|
+
var debug = [];
|
|
16791
16822
|
var occupied = [];
|
|
16792
16823
|
function overlaps(start, end) {
|
|
16793
16824
|
for (var i = 0; i < occupied.length; i++) {
|
|
@@ -16804,37 +16835,75 @@ function buildSendMessageExpr(conversationId, message) {
|
|
|
16804
16835
|
continue;
|
|
16805
16836
|
}
|
|
16806
16837
|
var matched = null;
|
|
16838
|
+
var debugItem = { raw: null, start: idx, matched: false, reason: 'not-parsed', uid: null, candidates: [] };
|
|
16807
16839
|
for (var i = 0; i < names.length; i++) {
|
|
16808
16840
|
var mentionText = '@' + names[i];
|
|
16809
16841
|
if (text.slice(idx, idx + mentionText.length) === mentionText && hasWordBoundary(text, idx + mentionText.length)) {
|
|
16810
|
-
|
|
16842
|
+
var entry = lookup[names[i]];
|
|
16843
|
+
matched = { uid: entry.uid, label: entry.label || names[i], start: idx, end: idx + mentionText.length };
|
|
16844
|
+
debugItem = { raw: mentionText, start: idx, matched: true, reason: 'exact', uid: matched.uid, replacement: '@' + matched.label, candidates: [{ uid: matched.uid, name: matched.label, score: 100 }] };
|
|
16811
16845
|
break;
|
|
16812
16846
|
}
|
|
16813
16847
|
}
|
|
16814
16848
|
if (!matched) {
|
|
16815
16849
|
var query = readMentionQuery(text, idx);
|
|
16816
16850
|
if (query) {
|
|
16817
|
-
var
|
|
16818
|
-
|
|
16819
|
-
|
|
16851
|
+
var fuzzy = resolveFuzzyMention(query.raw, lookup);
|
|
16852
|
+
debugItem = { raw: '@' + query.raw, start: query.start, matched: !!fuzzy.uid, reason: fuzzy.reason, uid: fuzzy.uid, replacement: fuzzy.label ? '@' + fuzzy.label : null, candidates: fuzzy.candidates };
|
|
16853
|
+
if (fuzzy.uid) {
|
|
16854
|
+
matched = { uid: fuzzy.uid, label: fuzzy.label || query.raw, start: query.start, end: query.end };
|
|
16820
16855
|
}
|
|
16821
16856
|
}
|
|
16822
16857
|
}
|
|
16823
16858
|
if (matched && !overlaps(matched.start, matched.end)) {
|
|
16824
|
-
|
|
16859
|
+
replacements.push({ uid: matched.uid, label: matched.label, start: matched.start, end: matched.end });
|
|
16825
16860
|
occupied.push({ start: matched.start, end: matched.end });
|
|
16861
|
+
debugItem.matched = true;
|
|
16862
|
+
debugItem.uid = matched.uid;
|
|
16863
|
+
debugItem.replacement = '@' + matched.label;
|
|
16826
16864
|
atIndex = matched.end;
|
|
16827
16865
|
} else {
|
|
16828
16866
|
atIndex = idx + 1;
|
|
16829
16867
|
}
|
|
16868
|
+
debug.push(debugItem);
|
|
16830
16869
|
}
|
|
16870
|
+
replacements.sort(function(a, b) { return a.start - b.start; });
|
|
16871
|
+
var finalText = '';
|
|
16872
|
+
var mentions = [];
|
|
16873
|
+
var cursor = 0;
|
|
16874
|
+
for (var r = 0; r < replacements.length; r++) {
|
|
16875
|
+
var replacement = '@' + replacements[r].label;
|
|
16876
|
+
finalText += text.slice(cursor, replacements[r].start);
|
|
16877
|
+
var finalStart = finalText.length;
|
|
16878
|
+
finalText += replacement;
|
|
16879
|
+
mentions.push({ uid: replacements[r].uid, start: finalStart, length: replacement.length, type: 0 });
|
|
16880
|
+
cursor = replacements[r].end;
|
|
16881
|
+
}
|
|
16882
|
+
finalText += text.slice(cursor);
|
|
16831
16883
|
mentions.sort(function(a, b) { return a.start - b.start; });
|
|
16832
|
-
return mentions;
|
|
16884
|
+
return { message: finalText, mentions: mentions, debug: debug, lookupSize: names.length };
|
|
16833
16885
|
}
|
|
16834
|
-
var
|
|
16886
|
+
var plan = extractMentions('${escapedMessage}');
|
|
16887
|
+
var mentions = plan.mentions;
|
|
16835
16888
|
var mentionTarget = mentions.length > 0 ? mentions[0].uid : null;
|
|
16836
16889
|
var mentionsArg = mentions.length > 0 ? mentions : null;
|
|
16837
|
-
|
|
16890
|
+
if (${dryRun ? "true" : "false"}) {
|
|
16891
|
+
return {
|
|
16892
|
+
ok: true,
|
|
16893
|
+
dryRun: true,
|
|
16894
|
+
conversationId: '${escapedConversationId}',
|
|
16895
|
+
inputMessage: '${escapedMessage}',
|
|
16896
|
+
message: plan.message,
|
|
16897
|
+
name: name,
|
|
16898
|
+
type: type,
|
|
16899
|
+
mentionTarget: mentionTarget,
|
|
16900
|
+
mentions: mentions,
|
|
16901
|
+
mentionCount: mentions.length,
|
|
16902
|
+
mentionDebug: plan.debug,
|
|
16903
|
+
mentionLookupSize: plan.lookupSize
|
|
16904
|
+
};
|
|
16905
|
+
}
|
|
16906
|
+
await conversation.sendMessage(plan.message, mentionTarget, mentionsArg, [], null, null, null, null, null, null);
|
|
16838
16907
|
return { ok: true, name: name, type: type, mentionCount: mentions.length };
|
|
16839
16908
|
} catch(e) {
|
|
16840
16909
|
return { ok: false, reason: e && e.message ? e.message : String(e) };
|
|
@@ -25363,6 +25432,7 @@ function parseIm1ReplyArgs(tokens) {
|
|
|
25363
25432
|
const targetTokens = [];
|
|
25364
25433
|
let thread;
|
|
25365
25434
|
let text;
|
|
25435
|
+
let dryRun = false;
|
|
25366
25436
|
while (rest.length > 0) {
|
|
25367
25437
|
const token = rest.shift();
|
|
25368
25438
|
switch (token) {
|
|
@@ -25372,6 +25442,10 @@ function parseIm1ReplyArgs(tokens) {
|
|
|
25372
25442
|
case "--text":
|
|
25373
25443
|
text = requireValue11(rest, token);
|
|
25374
25444
|
break;
|
|
25445
|
+
case "--dryrun":
|
|
25446
|
+
case "--dry-run":
|
|
25447
|
+
dryRun = true;
|
|
25448
|
+
break;
|
|
25375
25449
|
case "--source":
|
|
25376
25450
|
case "--endpoint":
|
|
25377
25451
|
targetTokens.push(token, requireValue11(rest, token));
|
|
@@ -25393,7 +25467,8 @@ function parseIm1ReplyArgs(tokens) {
|
|
|
25393
25467
|
source: target.source,
|
|
25394
25468
|
endpoint: target.endpoint,
|
|
25395
25469
|
thread,
|
|
25396
|
-
text
|
|
25470
|
+
text,
|
|
25471
|
+
dryRun
|
|
25397
25472
|
};
|
|
25398
25473
|
}
|
|
25399
25474
|
function parseTargetOptions(tokens) {
|