import type { ForecastResult } from "../forecast"; import type { DataStreamPurchaseDetails, ForecastDimensions, MarketplaceForecastDetails } from "../forecast/types"; import type { components } from "../generated/api-types"; /** * Every job type the backend can persist and return from the /jobs API. The * backend's job type is an open string, so this is the known set rather than a * closed enum. Anything outside it arrives as an {@link UnknownJob}. */ export declare const KNOWN_JOB_TYPES: readonly ["forecast", "forecast-internal", "nql-forecast", "costs", "materialize-view", "materialized_views_collect_access_rules_billing_data", "datasets_calculate_affected_rows", "datasets_calculate_column_stats", "datasets_create_table", "datasets_delete_table", "datasets_deliver_data", "datasets_enforce_row_ttl_retention_policy", "datasets_enforce_table_ttl_retention_policy", "datasets_execute_dml", "datasets_execute_select", "datasets_sample", "datasets_suggest_mappings", "datasets_truncate_table", "health_check", "model_inference_run", "model_training_run", "models_deliver_model", "models_train_classifier"]; export type JobType = (typeof KNOWN_JOB_TYPES)[number]; export type JobExecutionCluster = components["schemas"]["ExecutionClusterType"]; export interface JobRequestSourceApiUser { type: "api_user"; company_id: number; user_id: number; } export interface JobRequestSourceProcess { type: "process"; name: string; } /** * What asked for the job: a user calling the API, or an internal process * running on its own. * * This is the one field the SDK does not take from the spec. The spec describes * `request_source` as three independently optional fields, which covers both * shapes at once, narrows to neither, and has no `name` at all. The backend * models it as a closed sum type, so the union below is what actually arrives. */ export type JobRequestSource = JobRequestSourceApiUser | JobRequestSourceProcess; /** Swaps the spec's `request_source` for {@link JobRequestSource}. */ type WithRequestSource = Omit & { request_source: JobRequestSource; }; /** * Swaps a branch's `result` for a shape the SDK describes and the spec leaves * free-form. */ type WithResult = Omit & { result: R | null; }; /** * The fields every job carries, whatever its type. Each branch below adds * `type`, `input`, and `result` on top of these. * * `operator_type` is finer-grained than `type`: several job types can share one * operator, so `datasets_calculate_affected_rows` and `datasets_sample` both * run as `datasets_execute_select`. Where no operator of its own exists, it * equals `type`. */ export type BaseJob = WithRequestSource; export type ExplainInput = components["schemas"]["NqlForecastJobInput"]; /** * The forecast, or the reason it could not be produced. Exactly one of * `success` / `failure` is present; the absent branch is not sent as null. */ export type ExplainOutput = components["schemas"]["NqlForecastJobResult"]; export type ExplainJob = WithRequestSource; export type MaterializedViewInput = components["schemas"]["MaterializeViewJobInput"]; export type MaterializedViewRowStats = components["schemas"]["MaterializeViewJobRowStats"]; /** What a data plane reports after refreshing a view. */ export type RefreshMaterializedViewResult = components["schemas"]["MaterializeViewJobResult"]; /** * @deprecated The forecast-shaped result the Spark executor produced. The spec * attributes this shape to `nql-forecast` rather than to `materialize-view`, so * read it through {@link ExplainOutput} instead. */ export type MaterializedViewOutput = components["schemas"]["NqlForecastJobSuccess"]; export type MaterializedViewJob = WithRequestSource; export type CollectAccessRulesBillingDataInput = components["schemas"]["CollectAccessRulesBillingDataJobInput"]; export type CollectAccessRulesBillingDataResult = components["schemas"]["CollectAccessRulesBillingDataJobResult"]; export type CollectAccessRulesBillingDataJob = WithRequestSource; export type CalculateAffectedRowsInput = components["schemas"]["DatasetsCalculateAffectedRowsJobInput"]; export type CalculateAffectedRowsJob = WithRequestSource; export type CreateTableInput = components["schemas"]["DatasetsCreateTableJobInput"]; export type DatasetsCreateTableJob = WithRequestSource; export type TruncateTableInput = components["schemas"]["DatasetsTruncateTableJobInput"]; export type DatasetsTruncateTableJob = WithRequestSource; export type DeleteInput = components["schemas"]["DatasetsDeleteTableJobInput"]; export type DeleteResult = components["schemas"]["DatasetsDeleteTableJobResult"]; export type DatasetsDeleteTableJob = WithRequestSource; export type DeliverInput = components["schemas"]["DatasetsDeliverDataJobInput"]; export type DeliverResult = components["schemas"]["DatasetsDeliverDataJobResult"]; export type DatasetsDeliverDataJob = WithRequestSource; export type EnforceRowTtlRetentionPolicyInput = components["schemas"]["DatasetsEnforceRowTtlRetentionPolicyJobInput"]; export type DatasetsEnforceRowTtlRetentionPolicyJob = WithRequestSource; export type EnforceTableTtlRetentionPolicyInput = components["schemas"]["DatasetsEnforceTableTtlRetentionPolicyJobInput"]; export type DatasetsEnforceTableTtlRetentionPolicyJob = WithRequestSource; export type ExecuteDmlInput = components["schemas"]["DatasetsExecuteDmlJobInput"]; export type ExecuteDmlResult = components["schemas"]["DatasetsExecuteDmlJobResult"]; export type DatasetsExecuteDmlJob = WithRequestSource; export type SampleInput = components["schemas"]["DatasetsSampleJobInput"]; export type SampleResult = components["schemas"]["DatasetsSampleJobResult"]; export type DatasetsSampleJob = WithRequestSource; /** * The column types the statistics job reports. The spec types `data_type` as a * plain string so an unrecognised type still decodes, which is why * {@link ColumnDetails} does not use this union. */ export type ColumnStatDataType = "boolean" | "double" | "long" | "string" | "timestamp_tz" | "array" | "object"; export type EnabledColumnStatFlags = components["schemas"]["DatasetsCalculateColumnStatsFlags"]; export type ColumnDetails = components["schemas"]["DatasetsCalculateColumnStatsColumnDetails"]; export type StatsInput = components["schemas"]["DatasetsCalculateColumnStatsJobInputV1"]; export type StatsInputV2 = components["schemas"]["DatasetsCalculateColumnStatsJobInputV2"]; export type StatsResult = components["schemas"]["DatasetsCalculateColumnStatsJobResult"]; export type DatasetsCalculateColumnStatsJob = WithRequestSource; export type HealthCheckJob = WithRequestSource; export type ModelInferenceRunInput = components["schemas"]["ModelInferenceRunJobInput"]; export type ModelInferenceRunJobResult = components["schemas"]["ModelInferenceRunJobResult"]; export type ModelInferenceRunJob = WithRequestSource; export type ModelTrainingRunInput = components["schemas"]["ModelTrainingRunJobInput"]; /** Whatever the training operator posted on completion. The API stores it as * sent rather than reshaping it, so it has no fixed shape. */ export type ModelTrainingRunResult = components["schemas"]["JobResult"]; export type ModelTrainingRunJob = WithRequestSource; export type ModelsDeliverModelInput = components["schemas"]["ModelsDeliverModelJobInput"]; /** Whatever the delivery operator posted on completion. */ export type ModelsDeliverModelResult = components["schemas"]["JobResult"]; export type ModelsDeliverModelJob = WithRequestSource; /** * The spec leaves this job's `result` free-form because it never passes through * a typed class in the marketplace. {@link ModelsTrainClassifierResults} is the * SDK's own description of what the training operator actually posts, so the * result keeps that shape rather than widening to `unknown`. */ export type ModelsTrainClassifierJob = WithResult, ModelsTrainClassifierResults>; export interface ForecastInput { as_of?: string; dimensions: ForecastDimensions; fingerprint?: string; details: MarketplaceForecastDetails | DataStreamPurchaseDetails; } export type ForecastJob = BaseJob & { type: "forecast"; input: ForecastInput; result: ForecastResult | null; }; export type ForecastInternalJob = BaseJob & { type: "forecast-internal"; input: ForecastInput; result: ForecastResult | null; }; export interface CostsInput { as_of?: string; /** Subscription purchase details; shape mirrors the marketplace subscription model. */ details: unknown; } export type CostsJob = BaseJob & { type: "costs"; input: CostsInput; result: unknown; }; export interface ExecuteSelectInput { compiled_sql: string; } /** * The operator's raw SELECT output. Jobs that read a single value out of a * query carry this rather than a field of their own, so * {@link CalculateAffectedRowsJob} finds its count at * `rows[0].values.affected_rows`. */ export type ExecuteSelectResult = components["schemas"]["DatasetsCalculateAffectedRowsJobResult"]; export type DatasetsExecuteSelectJob = BaseJob & { type: "datasets_execute_select"; input: ExecuteSelectInput; result: ExecuteSelectResult | null; }; export interface SuggestMappingsInput { dataset_id: number; } export interface SuggestMappingsResult { result: string; } export type DatasetsSuggestMappingsJob = BaseJob & { type: "datasets_suggest_mappings"; input: SuggestMappingsInput; result: SuggestMappingsResult | null; }; /** * A job whose type the SDK does not know about. The backend's job type is an * open string and it stores `input` and `result` as arbitrary JSON, so a type * added after an SDK release lands here rather than failing to parse. Read * `type` to find out what arrived. */ export type UnknownJob = WithRequestSource; /** Discriminated union over every job type the SDK knows about. */ export type KnownJob = ForecastJob | ForecastInternalJob | ExplainJob | CostsJob | MaterializedViewJob | CollectAccessRulesBillingDataJob | CalculateAffectedRowsJob | DatasetsCalculateColumnStatsJob | DatasetsCreateTableJob | DatasetsDeleteTableJob | DatasetsDeliverDataJob | DatasetsEnforceRowTtlRetentionPolicyJob | DatasetsEnforceTableTtlRetentionPolicyJob | DatasetsExecuteDmlJob | DatasetsExecuteSelectJob | DatasetsSampleJob | DatasetsSuggestMappingsJob | DatasetsTruncateTableJob | HealthCheckJob | ModelInferenceRunJob | ModelTrainingRunJob | ModelsDeliverModelJob | ModelsTrainClassifierJob; export type Job = KnownJob | UnknownJob; /** * Narrows a job to the discriminated union of known types, enabling * exhaustive `switch (job.type)` handling in consumers: * * ```ts * if (isKnownJob(job)) { * switch (job.type) { * case "forecast": // job is ForecastJob * } * } * ``` */ export declare function isKnownJob(job: Job): job is KnownJob; export interface ModelsTrainClassifierTrainingSummary { total_features: number; feature_types: Record<"text" | "categorical" | "embedding" | "numeric", number>; test_accuracy: number; num_classes: number; class_names: Record; error?: unknown; } export interface ModelsTrainClassifierRegistryInfo { model_stored: boolean; model_name: string; model_version: string; registry_database: string; registry_schema: string; model_task: string; } export interface ModelsTrainClassifierMinimalMetrics { num_classes: number; class_names: Record; accuracy: number; f1_macro: number; precision_macro: number; recall_macro: number; } export interface ModelsTrainClassifierConfig { name: string; version: string; [key: string]: unknown; } export type ModelsTrainClassifierResults = { status: "success" | "error"; registry_info?: ModelsTrainClassifierRegistryInfo; num_categories: number; rows_processed: number; rows_dropped: number; metrics: { minimal: ModelsTrainClassifierMinimalMetrics; detailed: DetailedAnalytics; }; debug_info?: unknown; config: ModelsTrainClassifierConfig; training_summary: ModelsTrainClassifierTrainingSummary; }; export type Metric = Record> = { value: V; metadata: M; }; export interface AveragePredictionEntropy { correct_predictions: number; incorrect_predictions: number; entropy_difference: number; } export interface PerClassMetricsLabeledPost { class: string; f1_score: number; precision: number; recall: number; support: number; avg_confidence_when_correct: number; total_instances: number; correct_predictions: number; } export interface EntropyStats { min: number; max: number; mean: number; std: number; median: number; perplexity_mean: number; perplexity_median: number; normalized_perplexity_mean: number; normalized_perplexity_median: number; } export interface EntropyPrioritizationHistogram { min: number; max: number; count: number; inclusive_left: number; inclusive_right: number; } export interface TopEntropyRecord { entropy: number; top5_predicted_classes: [string, number][]; ID_COLUMN: string; LABEL_COLUMN: string; [key: string]: unknown; } export interface GlobalMetrics { num_documents_corpus_pre: Metric; num_documents_labeled_pre: Metric; percent_labeled_corpus_pre: Metric; label_distribution_labeled_pre: Metric, never>; class_imbalance_labeled_pre: Metric; missing_values_corpus_pre: Metric; duplicate_count_corpus_pre: Metric; accuracy_labeled_post: Metric; precision_macro_labeled_post: Metric; recall_macro_labeled_post: Metric; f1_macro_labeled_post: Metric; confusion_matrix_labeled_post: Metric; top_n_accuracy_labeled_post: Metric, never>; auc_roc_labeled_post: Metric; avg_prediction_entropy_labeled_post: Metric; per_class_metrics_labeled_post: Metric; entropy_stats: Metric; entropy_prioritization_histogram: Metric; top_entropy_records: Metric; } export type TopTermsValue = Record; export interface FeatureError { feature: string; prevalence_diff: number; incorrect_prevalence: number; correct_prevalence: number; ratio: number; } export interface ErrorConcentration { feature: string; records_with_feature: number; errors_with_feature: number; error_rate: number; overall_error_rate: number; error_lift: number; } export interface ErrorPredictionImportance { feature: string; correlation: number; p_value: number; abs_correlation: number; } export interface DynamicTextFeatureMetrics { [key: `${string}_avg_doc_length_corpus_pre`]: Metric; [key: `${string}_avg_doc_length_labeled_pre`]: Metric; [key: `${string}_ngram_vocab_size_corpus_pre`]: Metric; [key: `${string}_ngram_vocab_size_labeled_pre`]: Metric; [key: `${string}_ngram_top_terms_corpus_pre`]: Metric; [key: `${string}_ngram_top_terms_labeled_pre`]: Metric; [key: `${string}_ngram_diversity_corpus_pre`]: Metric; [key: `${string}_ngram_stopword_percentage_corpus_pre`]: Metric; [key: `${string}_ngram_entropy_corpus_pre`]: Metric; [key: `${string}_ngram_oov_rate_corpus_pre`]: Metric; [key: `${string}_ngram_sparsity_labeled_pre`]: Metric; [key: `${string}_ngram_diversity_labeled_pre`]: Metric; [key: `${string}_ngram_stopword_percentage_labeled_pre`]: Metric; [key: `${string}_ngram_entropy_labeled_pre`]: Metric; [key: `${string}_ngram_sparsity_labeled_post`]: Metric; [key: `${string}_ngram_top_oov_tokens`]: Metric; [key: `${string}_features_prevalent_in_errors`]: Metric; [key: `${string}_feature_error_concentration`]: Metric; [key: `${string}_error_prediction_importance`]: Metric; [key: `${string}_ttr_corpus_pre`]: Metric; [key: `${string}_ttr_labeled_pre`]: Metric; [key: `${string}_ttr_per_class_labeled_pre`]: Metric>; } export type DetailedAnalytics = { global: GlobalMetrics; } & { [dynamicKey: string]: DynamicTextFeatureMetrics; }; export {};