mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-21 20:04:55 +00:00
Complete the remaining pi-to-companion rename across companion-os, web, vm-orchestrator, docker, and archived fixtures. Verification: - semantic rg sweeps for Pi/piConfig/getPi/.pi runtime references - npm run check in apps/companion-os (fails in this worktree: biome not found) Co-authored-by: Codex <noreply@openai.com>
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
/**
|
|
* companion-channels — Built-in webhook adapter.
|
|
*
|
|
* POSTs message as JSON. The recipient field is the webhook URL.
|
|
*
|
|
* Config:
|
|
* {
|
|
* "type": "webhook",
|
|
* "method": "POST",
|
|
* "headers": { "Authorization": "Bearer ..." }
|
|
* }
|
|
*/
|
|
|
|
import type {
|
|
AdapterConfig,
|
|
ChannelAdapter,
|
|
ChannelMessage,
|
|
} from "../types.js";
|
|
|
|
export function createWebhookAdapter(config: AdapterConfig): ChannelAdapter {
|
|
const method = (config.method as string) ?? "POST";
|
|
const extraHeaders = (config.headers as Record<string, string>) ?? {};
|
|
|
|
return {
|
|
direction: "outgoing" as const,
|
|
|
|
async send(message: ChannelMessage): Promise<void> {
|
|
const res = await fetch(message.recipient, {
|
|
method,
|
|
headers: { "Content-Type": "application/json", ...extraHeaders },
|
|
body: JSON.stringify({
|
|
text: message.text,
|
|
source: message.source,
|
|
metadata: message.metadata,
|
|
timestamp: new Date().toISOString(),
|
|
}),
|
|
});
|
|
|
|
if (!res.ok) {
|
|
const err = await res.text().catch(() => "unknown error");
|
|
throw new Error(`Webhook error ${res.status}: ${err}`);
|
|
}
|
|
},
|
|
};
|
|
}
|