import {z} from 'zod' export type RankExpr = {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}, midpoint: number, exponent?: number | undefined}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}, midpoint: number, exponent?: number | undefined}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}, midpoint: number, exponent?: number | undefined}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}, midpoint: number, exponent?: number | undefined}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string} | {type: 'Sum', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Mult', exprs: Array} | {type: 'Div', exprs: Array} | {type: 'Max', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Min', exprs: Array<{type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}>} | {type: 'Log', base: number, expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}} | {type: 'Saturate', expr: {type: 'Attr', name: string} | {type: 'Const', value: number} | {type: 'BM25', field: string, query: string}, midpoint: number, exponent?: number | undefined}, midpoint: number, exponent?: number | undefined}, midpoint: number, exponent?: number | undefined}; export type UserFilter = {field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array}>} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array}>}>}; export type SearchUsersRequest = {query: string | Array | null, maxResults?: number | undefined, first?: number | undefined, filters?: ({field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array}>} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array} | {op: 'And' | 'Or', filters: Array<{field: string, op: 'Eq' | 'NotEq' | 'In' | 'NotIn' | 'Lt' | 'Lte' | 'Gt' | 'Gte' | 'Glob' | 'NotGlob' | 'IGlob' | 'NotIGlob' | 'Regex' | 'Contains' | 'NotContains' | 'ContainsAny' | 'NotContainsAny' | 'AnyLt' | 'AnyLte' | 'AnyGt' | 'AnyGte' | 'ContainsAllTokens', value: string | number | boolean | Array | Array}>}>}) | undefined, rankBy?: RankExpr | undefined, enablePagination?: boolean | undefined, after?: string | undefined, includeAttributes?: ({followers?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, following?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, stars?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, owns?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, contributes?: ({first: number, after?: string | undefined, filters?: UserFilter | undefined}) | undefined, devrank?: boolean | undefined, professional?: boolean | undefined, aggregates?: boolean | undefined, bestEmail?: boolean | undefined, revealEmails?: boolean | undefined}) | undefined, dataset?: ('standard' | 'professional') | undefined}; export type CreateApiSearchUsersArgs = {body: SearchUsersRequest}; export type CreateApiSearchUsersOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const professionalEducation = z.object({campus: z.string().nullable(), major: z.string().nullable(), specialization: z.string().nullable(), startDate: z.string().nullable(), endDate: z.string().nullable()}); export const professionalExperience = z.object({company: z.string().nullable(), title: z.string().nullable(), summary: z.string().nullable(), location: z.string().nullable(), industry: z.string().nullable(), startDate: z.string().nullable(), endDate: z.string().nullable(), startDateConfidence: z.string().nullable(), isCurrent: z.boolean().nullable()}); export const professionalProfile = z.object({firstName: z.string().nullable(), lastName: z.string().nullable(), linkedinUrl: z.string(), title: z.string().nullable(), headline: z.string().nullable(), organization: z.string().nullable(), currentIndustry: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), country: z.string().nullable(), location: z.string().nullable(), seniorityLevel: z.string().nullable(), seniority: z.string().nullable(), functionalArea: z.string().nullable(), expertise: z.array(z.string()).nullable(), certifications: z.array(z.string()).nullable(), awards: z.array(z.string()).nullable(), memberships: z.array(z.string()).nullable(), departments: z.array(z.string()).nullable(), patents: z.array(z.string()).nullable(), publications: z.array(z.string()).nullable(), priorIndustries: z.array(z.string()).nullable(), languages: z.array(z.string()).nullable(), connectionsCount: z.number().nullable(), followerCount: z.number().nullable(), hiring: z.boolean().nullable(), openToWork: z.boolean().nullable(), education: z.array(professionalEducation), experience: z.array(professionalExperience)}); export const userAggregates = z.object({totalStars: z.number()}); export const publicUser = z.object({id: z.string(), githubId: z.string(), login: z.string(), displayName: z.string().nullable().optional(), bio: z.string().nullable().optional(), company: z.string().nullable().optional(), location: z.string().nullable().optional(), websiteUrl: z.string().nullable().optional(), socialAccounts: z.array(z.object({provider: z.string(), url: z.string()})).nullable().optional(), emails: z.array(z.string()).nullable().optional(), resolvedCountry: z.string().nullable().optional(), resolvedState: z.string().nullable().optional(), resolvedCity: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), embeddedAt: z.string().nullable().optional(), score: z.number().optional()}); export const pageInfo = z.object({hasNextPage: z.boolean(), endCursor: z.string().nullable()}); export const paginatedUsers = z.object({edges: z.array(publicUser), pageInfo: pageInfo}); export const developerProfile = z.object({login: z.string(), userId: z.string().optional(), githubId: z.string().optional(), displayName: z.string().optional(), company: z.string().optional(), location: z.string().optional(), bio: z.string().optional(), accountCreatedAt: z.string().optional(), topRepos: z.array(z.object({name: z.string(), stargazerCount: z.number()})), devrank: z.object({tier: z.string(), crackedScore: z.number(), followersIn: z.number(), followingOut: z.number()}).optional(), linkedin: z.object({url: z.string().optional(), currentTitle: z.string().optional(), currentCompany: z.string().optional(), seniorityLevel: z.string().optional(), totalExperienceYears: z.number().optional(), connectionsCount: z.number().optional()}).optional()}); export const publicRepositoryWithGraph = z.object({id: z.string(), githubId: z.string(), ownerLogin: z.string(), name: z.string(), description: z.string().nullable().optional(), stargazerCount: z.number(), language: z.string().nullable().optional(), totalIssuesCount: z.number(), totalIssuesOpen: z.number(), totalIssuesClosed: z.number(), readmePreview: z.string().nullable().optional(), lastContributorLocations: z.array(z.string()).nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), embeddedAt: z.string().nullable().optional(), score: z.number().optional(), owner: z.object({id: z.string(), githubId: z.string(), login: z.string(), displayName: z.string().nullable().optional(), bio: z.string().nullable().optional(), company: z.string().nullable().optional(), location: z.string().nullable().optional(), websiteUrl: z.string().nullable().optional(), socialAccounts: z.array(z.object({provider: z.string(), url: z.string()})).nullable().optional(), emails: z.array(z.string()).nullable().optional(), resolvedCountry: z.string().nullable().optional(), resolvedState: z.string().nullable().optional(), resolvedCity: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), embeddedAt: z.string().nullable().optional(), score: z.number().optional()}).optional(), contributors: z.object({edges: z.array(publicUser), pageInfo: pageInfo}).optional(), contributorProfiles: z.array(developerProfile).optional(), starrers: z.object({edges: z.array(publicUser), pageInfo: pageInfo}).optional(), ownerDevrank: z.object({crackedScore: z.number(), tier: z.string(), rawScore: z.number(), trust: z.number(), pc: z.number(), followersIn: z.number(), followingOut: z.number(), community: z.number().int(), createdAt: z.string(), updatedAt: z.string()}).optional(), ownerProfessional: z.object({firstName: z.string().nullable(), lastName: z.string().nullable(), linkedinUrl: z.string(), title: z.string().nullable(), headline: z.string().nullable(), organization: z.string().nullable(), currentIndustry: z.string().nullable(), city: z.string().nullable(), state: z.string().nullable(), country: z.string().nullable(), location: z.string().nullable(), seniorityLevel: z.string().nullable(), seniority: z.string().nullable(), functionalArea: z.string().nullable(), expertise: z.array(z.string()).nullable(), certifications: z.array(z.string()).nullable(), awards: z.array(z.string()).nullable(), memberships: z.array(z.string()).nullable(), departments: z.array(z.string()).nullable(), patents: z.array(z.string()).nullable(), publications: z.array(z.string()).nullable(), priorIndustries: z.array(z.string()).nullable(), languages: z.array(z.string()).nullable(), connectionsCount: z.number().nullable(), followerCount: z.number().nullable(), hiring: z.boolean().nullable(), openToWork: z.boolean().nullable(), education: z.array(professionalEducation), experience: z.array(professionalExperience)}).optional()}); export const paginatedRepositories = z.object({edges: z.array(publicRepositoryWithGraph), pageInfo: pageInfo}); export const publicUserWithGraph = z.object({id: z.string(), githubId: z.string(), login: z.string(), displayName: z.string().nullable().optional(), bio: z.string().nullable().optional(), company: z.string().nullable().optional(), location: z.string().nullable().optional(), websiteUrl: z.string().nullable().optional(), socialAccounts: z.array(z.object({provider: z.string(), url: z.string()})).nullable().optional(), emails: z.array(z.string()).nullable().optional(), resolvedCountry: z.string().nullable().optional(), resolvedState: z.string().nullable().optional(), resolvedCity: z.string().nullable().optional(), createdAt: z.string().nullable().optional(), updatedAt: z.string().nullable().optional(), embeddedAt: z.string().nullable().optional(), score: z.number().optional(), devrank: z.object({crackedScore: z.number(), tier: z.string(), rawScore: z.number(), trust: z.number(), pc: z.number(), followersIn: z.number(), followingOut: z.number(), community: z.number().int(), createdAt: z.string(), updatedAt: z.string()}).optional(), professional: professionalProfile.optional(), aggregates: userAggregates.optional(), followers: paginatedUsers.optional(), following: z.object({edges: z.array(publicUser), pageInfo: pageInfo}).optional(), stars: paginatedRepositories.optional(), owns: z.object({edges: z.array(publicRepositoryWithGraph), pageInfo: pageInfo}).optional(), contributes: z.object({edges: z.array(publicRepositoryWithGraph), pageInfo: pageInfo}).optional(), bestEmail: z.string().nullable().optional()}).nullable(); export const searchUsersResponse = z.object({users: z.array(publicUserWithGraph), count: z.number(), pageInfo: z.object({hasNextPage: z.boolean(), endCursor: z.string().nullable()}).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Search GitHub users * * POST /search/users */ export const createApiSearchUsers = async (args: CreateApiSearchUsersArgs, options?: CreateApiSearchUsersOptions) => { const {baseUrl = "https://api.bountylab.io/v3", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/search/users${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(searchUsersResponse, await res.json()) };