soulsync 1.0.16 → 1.0.18
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/index.js +45 -31
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -88,17 +88,18 @@ function detectAuthMode(api) {
|
|
|
88
88
|
|
|
89
89
|
async function startOAuthLocal() {
|
|
90
90
|
const { createOAuthServer } = require('./src/oauth-server');
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
|
|
93
92
|
try {
|
|
94
93
|
const { server, port } = await createOAuthServer();
|
|
95
94
|
const callbackUrl = `http://localhost:${port}/callback`;
|
|
96
95
|
const state = crypto.randomBytes(16).toString('hex');
|
|
97
96
|
const authUrl = `${getCloudUrl()}/auth/oauth/start?port=${port}&callback=${encodeURIComponent(callbackUrl)}&state=${state}`;
|
|
98
|
-
|
|
97
|
+
|
|
99
98
|
console.log('[SoulSync] Opening browser for authorization...');
|
|
99
|
+
|
|
100
|
+
const open = (await import('open')).default;
|
|
100
101
|
await open(authUrl);
|
|
101
|
-
|
|
102
|
+
|
|
102
103
|
console.log('[SoulSync] Waiting for authorization...');
|
|
103
104
|
|
|
104
105
|
const { token } = await new Promise((resolve, reject) => {
|
|
@@ -352,33 +353,47 @@ async function startDeviceCodeFlow() {
|
|
|
352
353
|
|
|
353
354
|
module.exports = function register(api) {
|
|
354
355
|
console.log('[SoulSync] Registering plugin...');
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
if (
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
356
|
+
|
|
357
|
+
registerChatTools(api);
|
|
358
|
+
|
|
359
|
+
api.registerCli(
|
|
360
|
+
({ program }) => {
|
|
361
|
+
program
|
|
362
|
+
.command('soulsync:start')
|
|
363
|
+
.description('启动 SoulSync 同步服务')
|
|
364
|
+
.action(async () => {
|
|
365
|
+
if (!isAuthenticated()) {
|
|
366
|
+
console.log('[SoulSync] Not configured. Starting device authorization flow...');
|
|
367
|
+
|
|
368
|
+
const authMode = detectAuthMode(null);
|
|
369
|
+
let result;
|
|
370
|
+
|
|
371
|
+
if (authMode === 'oauth-local') {
|
|
372
|
+
result = await startOAuthLocal();
|
|
373
|
+
} else if (authMode === 'device-code-cli') {
|
|
374
|
+
result = await startDeviceCodeCLI();
|
|
375
|
+
} else {
|
|
376
|
+
result = await startDeviceCodeFlow();
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (result.success) {
|
|
380
|
+
console.log(result.message);
|
|
381
|
+
} else {
|
|
382
|
+
console.error(`[SoulSync] ${result.message}`);
|
|
383
|
+
}
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (pythonProcess) {
|
|
388
|
+
console.log('[SoulSync] Service already running');
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
startPythonService('--start');
|
|
371
393
|
});
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
break;
|
|
376
|
-
}
|
|
377
|
-
} else {
|
|
378
|
-
console.log('[SoulSync] Already authenticated, starting sync...');
|
|
379
|
-
startPythonService('--start');
|
|
380
|
-
registerChatTools(api);
|
|
381
|
-
}
|
|
394
|
+
},
|
|
395
|
+
{ commands: ['soulsync:start'] }
|
|
396
|
+
);
|
|
382
397
|
|
|
383
398
|
function registerChatTools(api) {
|
|
384
399
|
api.registerTool({
|
|
@@ -578,7 +593,6 @@ module.exports = function register(api) {
|
|
|
578
593
|
if (isAuthenticated()) {
|
|
579
594
|
console.log('[SoulSync] Auto-starting sync service...');
|
|
580
595
|
startPythonService('--start');
|
|
581
|
-
registerChatTools(api);
|
|
582
596
|
}
|
|
583
597
|
|
|
584
598
|
console.log('[SoulSync] Plugin loaded. Run "openclaw soulsync:start" to begin.');
|