Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

1.2 KB
Raw Blame
import * as NodeCrypto from "node:crypto";
import type { BotId } from "@akeru/contracts";

import type { BotInboxService } from "./service.ts";

export interface BrowserIncidentInput {
  readonly botId: BotId;
  readonly botName: string;
  readonly taskOrRoutine: string;
  readonly detail: string;
  readonly resourceKey: string;
}

export function browserIncidentKey(botId: BotId, resourceKey: string): string {
  const resourceId = NodeCrypto.createHash("sha256").update(resourceKey).digest("hex").slice(0, 16);

  return `browser:${botId}:${resourceId}`;
}

export function recordBrowserFailure(botInbox: BotInboxService, input: BrowserIncidentInput): void {
  botInbox.ensureOpen({
    incidentKey: browserIncidentKey(input.botId, input.resourceKey),
    kind: "browser-dead",
    botId: input.botId,
    botName: input.botName,
    taskOrRoutine: input.taskOrRoutine,
    lastFailure: input.detail,
    nextAction: "Retry the browser task after the managed browser is available.",
  });
}

export function resolveBrowserFailure(
  botInbox: BotInboxService,
  botId: BotId,
  resourceKey: string,
): void {
  botInbox.resolve(browserIncidentKey(botId, resourceKey));
  botInbox.resolve(`browser:${botId}`);
}