squad-openclaw 2026.2.2206 → 2026.2.2208
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.js +77 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2682,6 +2682,9 @@ function registerQuestionMethods(api) {
|
|
|
2682
2682
|
}
|
|
2683
2683
|
|
|
2684
2684
|
// src/sessions.ts
|
|
2685
|
+
import fs10 from "fs";
|
|
2686
|
+
import path11 from "path";
|
|
2687
|
+
import crypto4 from "crypto";
|
|
2685
2688
|
function asRecord(value) {
|
|
2686
2689
|
return value && typeof value === "object" ? value : null;
|
|
2687
2690
|
}
|
|
@@ -2743,6 +2746,64 @@ async function callGatewayAny(ctx, api, method, params) {
|
|
|
2743
2746
|
if (lastErr) throw lastErr;
|
|
2744
2747
|
throw new Error("Gateway method invocation API unavailable in plugin context");
|
|
2745
2748
|
}
|
|
2749
|
+
function parseAgentIdFromSessionKey(sessionKey) {
|
|
2750
|
+
const m = sessionKey.match(/^agent:([^:]+):/);
|
|
2751
|
+
return m?.[1] ?? null;
|
|
2752
|
+
}
|
|
2753
|
+
function ensureDir(dirPath) {
|
|
2754
|
+
fs10.mkdirSync(dirPath, { recursive: true });
|
|
2755
|
+
}
|
|
2756
|
+
function readSessionsMap(sessionsJsonPath) {
|
|
2757
|
+
try {
|
|
2758
|
+
const raw = fs10.readFileSync(sessionsJsonPath, "utf-8");
|
|
2759
|
+
const parsed = JSON.parse(raw);
|
|
2760
|
+
if (parsed && typeof parsed === "object") {
|
|
2761
|
+
return parsed;
|
|
2762
|
+
}
|
|
2763
|
+
} catch {
|
|
2764
|
+
}
|
|
2765
|
+
return {};
|
|
2766
|
+
}
|
|
2767
|
+
function writeSessionsMap(sessionsJsonPath, sessionsMap) {
|
|
2768
|
+
fs10.writeFileSync(sessionsJsonPath, JSON.stringify(sessionsMap, null, 2), "utf-8");
|
|
2769
|
+
}
|
|
2770
|
+
function createSessionOnDisk(input) {
|
|
2771
|
+
const requestedSessionKey = input.requestedSessionKey?.trim();
|
|
2772
|
+
const requestedAgentId = input.requestedAgentId?.trim();
|
|
2773
|
+
const derivedAgentId = requestedAgentId || (requestedSessionKey ? parseAgentIdFromSessionKey(requestedSessionKey) : null) || "main";
|
|
2774
|
+
const sessionKey = requestedSessionKey || `agent:${derivedAgentId}:${crypto4.randomUUID()}`;
|
|
2775
|
+
const stateDir = getOpenclawStateDir();
|
|
2776
|
+
const sessionsDir = path11.join(stateDir, "agents", derivedAgentId, "sessions");
|
|
2777
|
+
const sessionsJsonPath = path11.join(sessionsDir, "sessions.json");
|
|
2778
|
+
ensureDir(sessionsDir);
|
|
2779
|
+
const now = Date.now();
|
|
2780
|
+
const sessionsMap = readSessionsMap(sessionsJsonPath);
|
|
2781
|
+
const existing = sessionsMap[sessionKey];
|
|
2782
|
+
const sessionId = typeof existing?.sessionId === "string" && existing.sessionId.trim() ? existing.sessionId : crypto4.randomUUID();
|
|
2783
|
+
const jsonlPath = path11.join(sessionsDir, `${sessionId}.jsonl`);
|
|
2784
|
+
sessionsMap[sessionKey] = {
|
|
2785
|
+
...existing ?? {},
|
|
2786
|
+
sessionId,
|
|
2787
|
+
updatedAt: now,
|
|
2788
|
+
label: typeof existing?.label === "string" && existing.label.trim() ? existing.label : "New Session",
|
|
2789
|
+
totalTokens: typeof existing?.totalTokens === "number" ? existing.totalTokens : 0,
|
|
2790
|
+
lastMessageRole: existing?.lastMessageRole ?? "assistant",
|
|
2791
|
+
lastAssistantHasText: typeof existing?.lastAssistantHasText === "boolean" ? existing.lastAssistantHasText : true
|
|
2792
|
+
};
|
|
2793
|
+
writeSessionsMap(sessionsJsonPath, sessionsMap);
|
|
2794
|
+
if (!fs10.existsSync(jsonlPath)) {
|
|
2795
|
+
fs10.writeFileSync(jsonlPath, "", "utf-8");
|
|
2796
|
+
}
|
|
2797
|
+
return {
|
|
2798
|
+
key: sessionKey,
|
|
2799
|
+
sessionKey,
|
|
2800
|
+
sessionId,
|
|
2801
|
+
agentId: derivedAgentId,
|
|
2802
|
+
displayName: sessionKey,
|
|
2803
|
+
status: "active",
|
|
2804
|
+
createdAt: now
|
|
2805
|
+
};
|
|
2806
|
+
}
|
|
2746
2807
|
function registerSessionMethods(api) {
|
|
2747
2808
|
api.registerGatewayMethod(
|
|
2748
2809
|
"squad.sessions.create",
|
|
@@ -2788,6 +2849,22 @@ function registerSessionMethods(api) {
|
|
|
2788
2849
|
});
|
|
2789
2850
|
} catch (err2) {
|
|
2790
2851
|
const msg = err2 instanceof Error ? err2.message : String(err2);
|
|
2852
|
+
if (/gateway method invocation api unavailable in plugin context/i.test(msg)) {
|
|
2853
|
+
try {
|
|
2854
|
+
const local = createSessionOnDisk({
|
|
2855
|
+
requestedSessionKey: typeof sessionKey === "string" ? sessionKey : void 0,
|
|
2856
|
+
requestedAgentId: typeof agentId === "string" ? agentId : void 0
|
|
2857
|
+
});
|
|
2858
|
+
respond(true, local);
|
|
2859
|
+
return;
|
|
2860
|
+
} catch (fallbackErr) {
|
|
2861
|
+
const fallbackMsg = fallbackErr instanceof Error ? fallbackErr.message : String(fallbackErr);
|
|
2862
|
+
respond(false, {
|
|
2863
|
+
error: `Failed to create session (local fallback): ${fallbackMsg}`.slice(0, 500)
|
|
2864
|
+
});
|
|
2865
|
+
return;
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2791
2868
|
respond(false, {
|
|
2792
2869
|
error: `Failed to create session: ${msg}`.slice(0, 500)
|
|
2793
2870
|
});
|
package/package.json
CHANGED