mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Route ACP observer traffic over relay (#421)
Signed-off-by: Tyler Longwell <tlongwell@squareup.com> Co-authored-by: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> Co-authored-by: Tyler Longwell <tlongwell@squareup.com>
This commit is contained in:
co-authored by
tlongwell-block
Tyler Longwell
parent
0e9c02da2d
commit
fcec10547d
@@ -1,12 +1,13 @@
|
||||
import { invokeTauri } from "@/shared/api/tauri";
|
||||
import { sendAgentObserverControl } from "@/shared/api/observerRelay";
|
||||
import type { CancelManagedAgentTurnResult } from "@/shared/api/types";
|
||||
|
||||
export async function cancelManagedAgentTurn(
|
||||
pubkey: string,
|
||||
channelId: string,
|
||||
): Promise<CancelManagedAgentTurnResult> {
|
||||
return invokeTauri<CancelManagedAgentTurnResult>(
|
||||
"cancel_managed_agent_turn",
|
||||
{ pubkey, channelId },
|
||||
);
|
||||
await sendAgentObserverControl(pubkey, {
|
||||
type: "cancel_turn",
|
||||
channelId,
|
||||
});
|
||||
return { status: "sent" };
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { buildObserverControlEvent } from "@/shared/api/tauriObserver";
|
||||
import type { RelayEvent } from "@/shared/api/types";
|
||||
import { KIND_AGENT_OBSERVER_FRAME } from "@/shared/constants/kinds";
|
||||
import { relayClient } from "./relayClient";
|
||||
|
||||
export function subscribeToAgentObserverFrames(
|
||||
ownerPubkey: string,
|
||||
onEvent: (event: RelayEvent) => void,
|
||||
) {
|
||||
return relayClient.subscribeLive(
|
||||
{
|
||||
kinds: [KIND_AGENT_OBSERVER_FRAME],
|
||||
"#p": [ownerPubkey],
|
||||
limit: 0,
|
||||
since: Math.floor(Date.now() / 1_000),
|
||||
},
|
||||
onEvent,
|
||||
);
|
||||
}
|
||||
|
||||
export async function sendAgentObserverControl(
|
||||
agentPubkey: string,
|
||||
payload: unknown,
|
||||
) {
|
||||
await relayClient.preconnect();
|
||||
const event = await buildObserverControlEvent({ agentPubkey, payload });
|
||||
await relayClient.publishEvent(
|
||||
event,
|
||||
"Timed out while sending the agent control command.",
|
||||
"Failed to send the agent control command.",
|
||||
);
|
||||
}
|
||||
@@ -252,7 +252,6 @@ export type RawManagedAgent = {
|
||||
last_exit_code: number | null;
|
||||
last_error: string | null;
|
||||
log_path: string;
|
||||
observer_url: string | null;
|
||||
start_on_app_launch: boolean;
|
||||
backend: ManagedAgentBackend;
|
||||
backend_agent_id: string | null;
|
||||
@@ -863,7 +862,6 @@ export function fromRawManagedAgent(agent: RawManagedAgent): ManagedAgent {
|
||||
lastExitCode: agent.last_exit_code,
|
||||
lastError: agent.last_error,
|
||||
logPath: agent.log_path,
|
||||
observerUrl: agent.observer_url,
|
||||
startOnAppLaunch: agent.start_on_app_launch,
|
||||
backend: agent.backend,
|
||||
backendAgentId: agent.backend_agent_id,
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { RelayEvent } from "@/shared/api/types";
|
||||
import { invokeTauri } from "./tauri";
|
||||
|
||||
export async function decryptObserverEvent(
|
||||
event: RelayEvent,
|
||||
): Promise<unknown> {
|
||||
return invokeTauri<unknown>("decrypt_observer_event", {
|
||||
eventJson: JSON.stringify(event),
|
||||
});
|
||||
}
|
||||
|
||||
export async function buildObserverControlEvent(input: {
|
||||
agentPubkey: string;
|
||||
payload: unknown;
|
||||
}): Promise<RelayEvent> {
|
||||
const eventJson = await invokeTauri<string>("build_observer_control_event", {
|
||||
agentPubkey: input.agentPubkey,
|
||||
payload: input.payload,
|
||||
});
|
||||
return JSON.parse(eventJson) as RelayEvent;
|
||||
}
|
||||
@@ -307,7 +307,6 @@ export type ManagedAgent = {
|
||||
lastExitCode: number | null;
|
||||
lastError: string | null;
|
||||
logPath: string;
|
||||
observerUrl: string | null;
|
||||
startOnAppLaunch: boolean;
|
||||
backend: ManagedAgentBackend;
|
||||
backendAgentId: string | null;
|
||||
|
||||
Reference in New Issue
Block a user