Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

994 B
Raw Blame
import { isSkillhubPublishErrorCode } from '../../../../shared/skillhubPublishErrors';

export function normalizePublishErrorCode(errorCode: unknown): SkillhubPublishErrorCode {
  return isSkillhubPublishErrorCode(errorCode)
    ? errorCode
    : 'INTERNAL';
}

export function publishFailureMessage(message: unknown): string {
  if (message instanceof Error) return message.message;
  if (typeof message === 'string' && message.trim()) return message;
  return 'Publish failed';
}

export function buildPublishFailureEvent(
  name: string,
  errorCode: unknown,
  message: unknown,
): SkillhubPublishProgressEvent {
  return {
    phase: 'failed',
    name,
    errorCode: normalizePublishErrorCode(errorCode),
    message: publishFailureMessage(message),
  };
}

export function shouldDispatchPublishResultFallback(
  paramsName: string,
  activeName: string | null,
  failedProgressName: string | null,
): boolean {
  return activeName === paramsName && failedProgressName !== paramsName;
}