feat: implement OpenClaw process owner and runtime path utilities

- Add OpenClawProcessOwner class to manage the lifecycle of the OpenClaw process.
- Introduce utility functions for managing OpenClaw runtime paths.
- Update session store to normalize agent session keys and migrate existing keys.
- Refactor main process to handle local provider API routing through a new dispatch function.
- Enhance token usage writer to utilize a new session key parsing function.
- Create agents management store to handle agent data and interactions.
- Update chat store to integrate agent selection and session management.
- Introduce AgentsSection component for displaying agent information in the UI.
- Refactor HomePage to support agent selection and display current agent.
- Update routing to reflect new agents page structure.
This commit is contained in:
duanshuwen
2026-04-17 21:32:06 +08:00
parent eca70425cf
commit e9f3a29886
33 changed files with 1526 additions and 2428 deletions

View File

@@ -2,6 +2,7 @@ import * as fs from 'fs';
import * as path from 'path';
import { app } from 'electron';
import logManager from '@electron/service/logger';
import { normalizeAgentSessionKey } from '@runtime/lib/agents';
import type { RawMessage } from '@runtime/shared/chat-model';
let sessionsFilePath: string | null = null;
@@ -41,12 +42,21 @@ class SessionStore {
string,
Omit<SessionEntry, 'activeRun'>
>;
let migrated = false;
for (const [key, entry] of Object.entries(data)) {
this.sessions.set(key, {
const normalizedKey = normalizeAgentSessionKey(key);
if (normalizedKey !== key) {
migrated = true;
}
this.sessions.set(normalizedKey, {
...entry,
key: normalizedKey,
activeRun: undefined,
});
}
if (migrated) {
this.saveToDisk();
}
}
} catch (e) {
logManager.error('Failed to load sessions from disk:', e);
@@ -73,21 +83,22 @@ class SessionStore {
getOrCreate(key: string): SessionEntry {
this.ensureLoaded();
let session = this.sessions.get(key);
const normalizedKey = normalizeAgentSessionKey(key);
let session = this.sessions.get(normalizedKey);
if (!session) {
session = {
key,
key: normalizedKey,
messages: [],
updatedAt: Date.now(),
};
this.sessions.set(key, session);
this.sessions.set(normalizedKey, session);
}
return session;
}
get(key: string): SessionEntry | undefined {
this.ensureLoaded();
return this.sessions.get(key);
return this.sessions.get(normalizeAgentSessionKey(key));
}
getAllKeys(): string[] {
@@ -114,18 +125,18 @@ class SessionStore {
}
clearActiveRun(key: string): void {
const session = this.sessions.get(key);
const session = this.sessions.get(normalizeAgentSessionKey(key));
if (session) {
session.activeRun = undefined;
}
}
getActiveRun(key: string): { runId: string; abortController: AbortController } | undefined {
return this.sessions.get(key)?.activeRun;
return this.sessions.get(normalizeAgentSessionKey(key))?.activeRun;
}
deleteSession(key: string): void {
this.sessions.delete(key);
this.sessions.delete(normalizeAgentSessionKey(key));
this.saveToDisk();
}
}