mirror of
https://github.com/block/buzz.git
synced 2026-12-01 13:42:45 +00: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:
32
desktop/src/shared/api/observerRelay.ts
Normal file
32
desktop/src/shared/api/observerRelay.ts
Normal file
@@ -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.",
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user