adp-openclaw 0.0.52 → 0.0.54
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/package.json +1 -1
- package/src/adp-upload-tool.ts +1 -1
- package/src/session-history.ts +64 -1
package/package.json
CHANGED
package/src/adp-upload-tool.ts
CHANGED
|
@@ -68,7 +68,7 @@ interface FileMetadata {
|
|
|
68
68
|
// ==================== 常量配置 ====================
|
|
69
69
|
|
|
70
70
|
/** 获取临时密钥的接口地址 */
|
|
71
|
-
const CREDENTIAL_API_URL = "https://wss.lke.cloud.tencent.com/
|
|
71
|
+
const CREDENTIAL_API_URL = "https://wss.lke.cloud.tencent.com/v1/gateway/storage/get_credential";
|
|
72
72
|
|
|
73
73
|
/** 请求超时时间 (毫秒) */
|
|
74
74
|
const REQUEST_TIMEOUT_MS = 30000;
|
package/src/session-history.ts
CHANGED
|
@@ -518,6 +518,69 @@ function findOpenClawCli(config: SessionFileConfig): string | null {
|
|
|
518
518
|
return null;
|
|
519
519
|
}
|
|
520
520
|
|
|
521
|
+
/**
|
|
522
|
+
* Extract valid JSON from CLI output that may contain TUI decoration characters
|
|
523
|
+
* (e.g. │, ◇, ◆, spinner frames) mixed into stdout.
|
|
524
|
+
*/
|
|
525
|
+
function extractJsonFromOutput(raw: string): string {
|
|
526
|
+
const trimmed = raw.trim();
|
|
527
|
+
|
|
528
|
+
// Fast path: already valid JSON
|
|
529
|
+
if (
|
|
530
|
+
(trimmed.startsWith("{") && trimmed.endsWith("}")) ||
|
|
531
|
+
(trimmed.startsWith("[") && trimmed.endsWith("]"))
|
|
532
|
+
) {
|
|
533
|
+
return trimmed;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// Try to find the first top-level JSON object or array in the output
|
|
537
|
+
const jsonStart = trimmed.search(/[\[{]/);
|
|
538
|
+
if (jsonStart === -1) {
|
|
539
|
+
return trimmed; // no JSON-like content, return as-is and let caller handle the error
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
const opener = trimmed[jsonStart];
|
|
543
|
+
const closer = opener === "{" ? "}" : "]";
|
|
544
|
+
|
|
545
|
+
// Walk forward tracking brace/bracket depth to find the matching close
|
|
546
|
+
let depth = 0;
|
|
547
|
+
let inString = false;
|
|
548
|
+
let escaped = false;
|
|
549
|
+
|
|
550
|
+
for (let i = jsonStart; i < trimmed.length; i++) {
|
|
551
|
+
const ch = trimmed[i];
|
|
552
|
+
|
|
553
|
+
if (escaped) {
|
|
554
|
+
escaped = false;
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
if (ch === "\\") {
|
|
558
|
+
if (inString) escaped = true;
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
561
|
+
if (ch === '"') {
|
|
562
|
+
inString = !inString;
|
|
563
|
+
continue;
|
|
564
|
+
}
|
|
565
|
+
if (inString) continue;
|
|
566
|
+
|
|
567
|
+
if (ch === opener || ch === (opener === "{" ? "[" : "{")) {
|
|
568
|
+
// count both kinds of nesting
|
|
569
|
+
if (ch === "{" || ch === "[") depth++;
|
|
570
|
+
}
|
|
571
|
+
if (ch === closer || ch === (closer === "}" ? "]" : "}")) {
|
|
572
|
+
if (ch === "}" || ch === "]") depth--;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (depth === 0) {
|
|
576
|
+
return trimmed.slice(jsonStart, i + 1);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Fallback: return from jsonStart onwards
|
|
581
|
+
return trimmed.slice(jsonStart);
|
|
582
|
+
}
|
|
583
|
+
|
|
521
584
|
/**
|
|
522
585
|
* Execute an openclaw CLI command and return the result.
|
|
523
586
|
* @param subcommands - Array of subcommands, e.g. ["gateway", "call", "chat.history"] or ["sessions"]
|
|
@@ -593,7 +656,7 @@ async function executeClawCommand(
|
|
|
593
656
|
log?.error?.(`[session-history] CLI exited with code ${code}: ${stderr}`);
|
|
594
657
|
reject(new Error(`CLI exited with code ${code}: ${stderr}`));
|
|
595
658
|
} else {
|
|
596
|
-
resolve(stdout);
|
|
659
|
+
resolve(extractJsonFromOutput(stdout));
|
|
597
660
|
}
|
|
598
661
|
});
|
|
599
662
|
});
|