Restore managed agents on launch and recover chat after relay restarts (#93)

This commit is contained in:
Wes
2026-03-17 13:48:02 -07:00
committed by GitHub
parent 6ecd04819e
commit 0d73fe7632
22 changed files with 1131 additions and 493 deletions

View File

@@ -231,6 +231,7 @@ type RawManagedAgent = {
last_exit_code: number | null;
last_error: string | null;
log_path: string;
start_on_app_launch: boolean;
};
type RawCreateManagedAgentResponse = {
@@ -500,6 +501,7 @@ function cloneManagedAgent(agent: MockManagedAgent): RawManagedAgent {
last_exit_code: agent.last_exit_code,
last_error: agent.last_error,
log_path: agent.log_path,
start_on_app_launch: agent.start_on_app_launch,
};
}
@@ -2142,6 +2144,7 @@ async function handleCreateManagedAgent(args: {
tokenScopes?: string[];
tokenName?: string;
spawnAfterCreate?: boolean;
startOnAppLaunch?: boolean;
};
}): Promise<RawCreateManagedAgentResponse> {
const name = args.input.name.trim();
@@ -2179,6 +2182,7 @@ async function handleCreateManagedAgent(args: {
last_exit_code: null,
last_error: null,
log_path: `/tmp/mock-agent-${pubkey}.log`,
start_on_app_launch: args.input.startOnAppLaunch ?? true,
private_key_nsec: `nsec1mock${pubkey.slice(0, 20)}`,
api_token: token,
log_lines: [
@@ -2253,6 +2257,16 @@ async function handleDeleteManagedAgent(args: {
syncMockRelayAgentsFromManagedAgents();
}
async function handleSetManagedAgentStartOnAppLaunch(args: {
pubkey: string;
startOnAppLaunch: boolean;
}): Promise<RawManagedAgent> {
const agent = getMockManagedAgent(args.pubkey);
agent.start_on_app_launch = args.startOnAppLaunch;
agent.updated_at = new Date().toISOString();
return cloneManagedAgent(agent);
}
async function handleMintManagedAgentToken(args: {
input: {
pubkey: string;
@@ -2848,6 +2862,12 @@ export function maybeInstallE2eTauriMocks() {
return handleStopManagedAgent(
payload as Parameters<typeof handleStopManagedAgent>[0],
);
case "set_managed_agent_start_on_app_launch":
return handleSetManagedAgentStartOnAppLaunch(
payload as Parameters<
typeof handleSetManagedAgentStartOnAppLaunch
>[0],
);
case "delete_managed_agent":
return handleDeleteManagedAgent(
payload as Parameters<typeof handleDeleteManagedAgent>[0],