Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

820 B
Raw Blame
import type { ExitCodeValue } from '@/errors/codes'
import type { FoldResult } from '@/protocol/fold'
import { ExitCode } from '@/errors/codes'
import { FOLD_STATUS, FOLD_TABLE, foldAnyEvent } from '@/protocol/fold'

export function newFoldResult(): FoldResult {
  return { status: FOLD_STATUS.Incomplete, text: { answer: '' }, hints: [] }
}

export function foldEvent(result: FoldResult, name: string, event: Record<string, unknown>): void {
  foldAnyEvent(result, event)
  FOLD_TABLE[name]?.(result, event)
}

export function finishFold(result: FoldResult): FoldResult {
  if (result.status !== FOLD_STATUS.Incomplete) delete result.text.by_source
  return result
}

export function exitCodeFor(result: FoldResult): ExitCodeValue {
  return result.status === FOLD_STATUS.Failed ? ExitCode.Generic : ExitCode.Success
}