Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.5 KB
Raw Blame
import type {
  AgentSignalSourceEventInput,
  AgentSignalSourceType,
} from '@lobechat/agent-signal/source';

import { lambdaClient } from '@/libs/trpc/client';

type ClientGatewaySourceType = Extract<AgentSignalSourceType, `client.${string}`>;

type ClientGatewaySourceEventInput<TSourceType extends ClientGatewaySourceType> =
  AgentSignalSourceEventInput<TSourceType>;

export interface ListAgentSignalReceiptsParams {
  agentId: string;
  cursor?: number;
  limit?: number;
  sinceCreatedAt?: number;
  topicId: string;
}

export interface RollbackAgentSignalReceiptParams {
  agentDocumentId?: string;
  /** Skill receipts only. */
  documentId?: string;
  /** Skill receipts only. */
  historyId?: string;
  receiptId: string;
}

class AgentSignalService {
  listReceipts = async (params: ListAgentSignalReceiptsParams) => {
    return lambdaClient.agentSignal.listReceipts.query(params);
  };

  rollbackReceipt = async (params: RollbackAgentSignalReceiptParams) => {
    return lambdaClient.agentSignal.rollbackReceipt.mutate(params);
  };

  emitSourceEvent = async (payload: ClientGatewaySourceEventInput<ClientGatewaySourceType>) => {
    return lambdaClient.agentSignal.emitSourceEvent.mutate(payload);
  };

  emitClientGatewaySourceEvent = async <TSourceType extends ClientGatewaySourceType>(
    payload: ClientGatewaySourceEventInput<TSourceType>,
  ) => {
    return this.emitSourceEvent({
      ...payload,
      timestamp: payload.timestamp ?? Date.now(),
    });
  };
}

export const agentSignalService = new AgentSignalService();