social-agent-cli 4.1.0 → 4.2.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/ai/runner.ts +9 -4
- package/core/upload-helper.ts +17 -17
- package/maps/linkedin.json +2 -1
- package/maps/x.json +2 -1
- package/package.json +1 -1
- package/platforms/browser/driver.ts +26 -17
package/ai/runner.ts
CHANGED
|
@@ -53,11 +53,12 @@ export async function runCommand(platform: string, command: string): Promise<voi
|
|
|
53
53
|
|
|
54
54
|
let steps = [...map.steps];
|
|
55
55
|
|
|
56
|
-
// Image varsa:
|
|
56
|
+
// Image varsa: metin yazma step'inden ÖNCE upload step ekle (LinkedIn'de önce fotoğraf yüklenmeli)
|
|
57
57
|
if (image && !steps.some(s => s.action === "upload")) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const typeIdx = steps.findIndex(s => s.action === "type");
|
|
59
|
+
const insertIdx = typeIdx > -1 ? typeIdx : steps.findLastIndex(s => s.action === "click");
|
|
60
|
+
if (insertIdx > -1) {
|
|
61
|
+
steps.splice(insertIdx, 0, {
|
|
61
62
|
action: "upload" as any,
|
|
62
63
|
description: "Fotoğraf yükle",
|
|
63
64
|
selector: "input[type='file']",
|
|
@@ -69,7 +70,9 @@ export async function runCommand(platform: string, command: string): Promise<voi
|
|
|
69
70
|
|
|
70
71
|
// Step'leri çalıştır
|
|
71
72
|
const errors: string[] = [];
|
|
73
|
+
let aborted = false;
|
|
72
74
|
for (let idx = 0; idx < steps.length; idx++) {
|
|
75
|
+
if (aborted) break;
|
|
73
76
|
const s = steps[idx];
|
|
74
77
|
try {
|
|
75
78
|
console.log(` ${idx + 1}. ${s.description}`);
|
|
@@ -77,6 +80,8 @@ export async function runCommand(platform: string, command: string): Promise<voi
|
|
|
77
80
|
} catch (err: any) {
|
|
78
81
|
errors.push(`Step ${idx + 1} (${s.description}): ${err.message}`);
|
|
79
82
|
console.log(` ✗ ${err.message}`);
|
|
83
|
+
// Upload hatası → geri kalanı çalıştırma (fotoğrafsız post göndermesin)
|
|
84
|
+
if (s.action === "upload") { aborted = true; }
|
|
80
85
|
}
|
|
81
86
|
}
|
|
82
87
|
|
package/core/upload-helper.ts
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Kullanım: npx tsx core/upload-helper.ts <cdp-port> <button-selector> <file-path>
|
|
2
|
+
* Upload helper - Playwright fileChooser ile dosya yükler
|
|
3
|
+
* Kullanım: npx tsx core/upload-helper.ts <cdp-port> <click-selector> <file-path>
|
|
6
4
|
*/
|
|
7
5
|
import { chromium } from "playwright";
|
|
8
6
|
|
|
9
7
|
const [, , port, selector, filePath] = process.argv;
|
|
10
8
|
|
|
11
9
|
if (!port || !selector || !filePath) {
|
|
12
|
-
console.error("Kullanım: npx tsx core/upload-helper.ts <port> <selector> <file-path>");
|
|
13
10
|
process.exit(1);
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
async function upload() {
|
|
17
14
|
const browser = await chromium.connectOverCDP(`http://127.0.0.1:${port}`);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
const page = pages
|
|
15
|
+
const pages = browser.contexts()[0].pages();
|
|
16
|
+
// LinkedIn sayfasını bul
|
|
17
|
+
const page = pages.find(p => p.url().includes("linkedin.com")) || pages[0];
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
page.click(selector),
|
|
25
|
-
]);
|
|
19
|
+
// fileChooser promise'ı ÖNCE başlat
|
|
20
|
+
const fcPromise = page.waitForEvent("filechooser", { timeout: 10000 });
|
|
26
21
|
|
|
27
|
-
|
|
22
|
+
// Butona tıkla
|
|
23
|
+
try { await page.click(selector, { timeout: 5000 }); } catch {}
|
|
24
|
+
|
|
25
|
+
// fileChooser'ı yakala ve dosya set et
|
|
26
|
+
const fc = await fcPromise;
|
|
27
|
+
await fc.setFiles(filePath);
|
|
28
28
|
console.log("OK");
|
|
29
|
+
|
|
30
|
+
// Hemen çık - beklemeden
|
|
31
|
+
process.exit(0);
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
upload().catch((
|
|
32
|
-
console.error(e.message);
|
|
33
|
-
process.exit(1);
|
|
34
|
-
});
|
|
34
|
+
upload().catch(() => process.exit(1));
|
package/maps/linkedin.json
CHANGED
package/maps/x.json
CHANGED
package/package.json
CHANGED
|
@@ -205,25 +205,34 @@ export class BrowserDriver {
|
|
|
205
205
|
} catch {}
|
|
206
206
|
|
|
207
207
|
// 2. Playwright fileChooser ile dene (LinkedIn gibi native dialog kullananlar için)
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
// Snapshot'tan medya butonunun aria-label'ını bul
|
|
209
|
+
let btnSel = "button[aria-label*='Medya']";
|
|
210
210
|
try {
|
|
211
|
-
const
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
execSync(
|
|
215
|
-
`npx tsx "${join(pkgDir, 'core/upload-helper.ts')}" ${CDP_PORT} "${btnSel}" "${filePath}"`,
|
|
216
|
-
{ stdio: "pipe", timeout: 15000 }
|
|
217
|
-
);
|
|
218
|
-
this.cmd("wait 3000");
|
|
219
|
-
// Editör modal'ı varsa kapat
|
|
220
|
-
try {
|
|
221
|
-
this.cmd(`eval "document.querySelectorAll('button').forEach(b => { var t=b.textContent.trim().toLowerCase(); if(t==='ileri' || t==='bitti' || t==='done' || t==='next' || t==='tamam') b.click() })"`);
|
|
222
|
-
this.cmd("wait 1000");
|
|
223
|
-
} catch {}
|
|
224
|
-
if (step.waitMs) this.cmd(`wait ${step.waitMs}`);
|
|
225
|
-
return;
|
|
211
|
+
const snap = this.cmd("snapshot -i -c", 5000);
|
|
212
|
+
const mediaMatch = snap.match(/button "([^"]*(?:Medya|media|Fotoğraf|photo|Dosya|file|video)[^"]*)"/i);
|
|
213
|
+
if (mediaMatch) btnSel = `button[aria-label='${mediaMatch[1]}']`;
|
|
226
214
|
} catch {}
|
|
215
|
+
try {
|
|
216
|
+
const thisDir = new URL(".", import.meta.url).pathname;
|
|
217
|
+
const pkgDir = process.env.SOCIAL_AGENT_PKG || join(thisDir, "../..");
|
|
218
|
+
console.log(` [upload] helper: ${btnSel}`);
|
|
219
|
+
const helperResult = execSync(
|
|
220
|
+
`npx tsx "${join(pkgDir, 'core/upload-helper.ts')}" ${CDP_PORT} "${btnSel}" "${filePath}"`,
|
|
221
|
+
{ encoding: "utf-8", timeout: 60000 }
|
|
222
|
+
).trim();
|
|
223
|
+
if (helperResult === "OK") {
|
|
224
|
+
// Editör modal kapatma - "İleri" butonuna tıkla (3 saniye bekle, modal yüklensin)
|
|
225
|
+
setTimeout(() => {}, 3000);
|
|
226
|
+
try {
|
|
227
|
+
execSync(`agent-browser --cdp ${CDP_PORT} wait 3000`, { stdio: "pipe", timeout: 10000 });
|
|
228
|
+
execSync(`agent-browser --cdp ${CDP_PORT} eval "document.querySelectorAll('button').forEach(b => { var t=b.textContent.trim().toLowerCase(); if(t==='ileri' || t==='bitti' || t==='done' || t==='next') b.click() })"`, { stdio: "pipe", timeout: 5000 });
|
|
229
|
+
execSync(`agent-browser --cdp ${CDP_PORT} wait 2000`, { stdio: "pipe", timeout: 5000 });
|
|
230
|
+
} catch {}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
} catch (e: any) {
|
|
234
|
+
console.log(` [upload] helper hata: ${e.message?.substring(0, 80)}`);
|
|
235
|
+
}
|
|
227
236
|
|
|
228
237
|
throw new Error(`Upload: ${filePath}`);
|
|
229
238
|
}
|