import type { CodaliGatewayRequest, CodaliGatewayResult } from "../gateway/CodaliGatewayTypes.js"; import { type CodaliGatewayRunTrace } from "../gateway/CodaliGatewayStore.js"; import { type CodaliStorageDatasetKind, type CodaliStorageDatasetRecord, type CodaliStorageObjectPrivacyFlags, type CodaliStorageObjectRef, type CodaliStorageObjectRefKind, type CodaliStorageObjectRetentionClass, type CodaliStoragePrivacyMetadata } from "./CodaliStorageContracts.js"; export declare const GATEWAY_DATASET_SERVICE_SIGNATURE_VERSION = "codali.storage.hmac.v1"; export declare const DEFAULT_GATEWAY_DATASET_SERVICE_ENDPOINT = "/v1/gateway/batches"; export interface GatewayDatasetStorageScope { tenantId: string; productId: string; deploymentId: string; runId: string; } export type GatewayDatasetStoreWriteStatus = "stored" | "queued" | "skipped" | "failed"; export interface GatewayDatasetStoreWriteResult { accepted: boolean; status: GatewayDatasetStoreWriteStatus; recordCount: number; objectCount?: number; idempotencyKey?: string; batchId?: string; replayed?: boolean; fallbackUsed?: boolean; errors?: string[]; metadata?: Record; } export interface GatewayDatasetStoreCollectInput { scope: GatewayDatasetStorageScope; records: CodaliStorageDatasetRecord[]; idempotencyKey?: string; metadata?: Record; } export interface GatewayDatasetStore { collect(input: GatewayDatasetStoreCollectInput): Promise; } export interface GatewayDatasetObjectPutInput { scope: GatewayDatasetStorageScope; payload: unknown; ownerType: string; ownerId: string; kind?: CodaliStorageObjectRefKind; mimeType?: string; retentionClass?: CodaliStorageObjectRetentionClass; privacyFlags?: Partial; metadata?: Record; } export interface GatewayDatasetObjectStore { putObject(input: GatewayDatasetObjectPutInput): Promise; readObject?(ref: CodaliStorageObjectRef): Promise; } export type GatewayDatasetGoldTargetKind = "accepted" | "corrected" | "reviewed"; export interface GatewayDatasetGoldTargetInput { id?: string; kind: GatewayDatasetGoldTargetKind; input?: unknown; target?: unknown; sourceRecordId?: string; sourceModelCallId?: string; failedAttemptRecordId?: string; failedAttemptModelCallId?: string; reviewerId?: string; reasons?: string[]; score?: number; labels?: string[]; metadata?: Record; } export interface GatewayDatasetGatewayCollectionOptions { enabled?: boolean; objectStore?: GatewayDatasetObjectStore; fallbackStore?: GatewayDatasetStore; scope?: Partial; privacy?: Partial; privacyFlags?: Partial; datasetKind?: CodaliStorageDatasetKind; idempotencyKey?: string; trace?: CodaliGatewayRunTrace; traceLoader?: () => Promise; collectModelCalls?: boolean; collectSchemaFailures?: boolean; collectGoldTargets?: boolean; collectRagRetrievals?: boolean; collectToolDecisions?: boolean; collectEvidenceItems?: boolean; collectContextPacks?: boolean; collectFinalAnswers?: boolean; collectArtifacts?: boolean; collectPolicyEvents?: boolean; goldTargets?: GatewayDatasetGoldTargetInput[]; metadata?: Record; now?: () => Date; onError?: (error: unknown) => void; onResult?: (result: GatewayDatasetStoreWriteResult) => void; } export interface GatewayDatasetGatewayCollectionInput extends GatewayDatasetGatewayCollectionOptions { store: GatewayDatasetStore; request: CodaliGatewayRequest; result: CodaliGatewayResult; } export interface GatewayDatasetServiceClientOptions { baseUrl: string; serviceToken: string; hmacSecret?: string; endpointPath?: string; batchSize?: number; maxRetries?: number; retryBaseMs?: number; timeoutMs?: number; fallbackStore?: GatewayDatasetStore; fetch?: GatewayDatasetFetch; now?: () => Date; nonceFactory?: () => string; } export interface GatewayDatasetFetchRequest { method: "GET" | "POST"; headers: Record; body?: string; signal?: AbortSignal; } export interface GatewayDatasetFetchResponse { ok: boolean; status: number; statusText?: string; text(): Promise; } export type GatewayDatasetFetch = (url: string, request: GatewayDatasetFetchRequest) => Promise; export interface LocalJsonlGatewayDatasetStoreOptions { directory: string; recordsFileName?: string; now?: () => Date; } export interface LocalJsonlGatewayDatasetObjectStoreOptions { directory: string; now?: () => Date; } export declare class GatewayDatasetStoreError extends Error { readonly code: string; constructor(code: string, message: string); } export declare class GatewayDatasetServiceClientError extends Error { readonly code: string; readonly status?: number; readonly retryable: boolean; constructor(input: { code: string; message: string; status?: number; retryable?: boolean; }); } export declare const canonicalizeGatewayDatasetJson: (value: unknown) => string; export declare const hashGatewayDatasetRequestBody: (body: unknown) => string; export declare const hashGatewayDatasetValue: (value: unknown) => string; export declare const createGatewayDatasetLocalOnlyPrivacy: (overrides?: Partial) => CodaliStoragePrivacyMetadata; export declare const createGatewayDatasetLocalOnlyObjectPrivacyFlags: (overrides?: Partial) => CodaliStorageObjectPrivacyFlags; export declare const gatewayDatasetScopeFromGatewayResult: (request: CodaliGatewayRequest, result: CodaliGatewayResult, overrides?: Partial) => GatewayDatasetStorageScope; export declare const buildGatewayDatasetIdempotencyKey: (scope: GatewayDatasetStorageScope, records: readonly CodaliStorageDatasetRecord[]) => string; export declare const buildGatewayDatasetServiceSignatureHeaders: (input: { scope: GatewayDatasetStorageScope; body: unknown; hmacSecret: string; timestamp: string; nonce: string; }) => Record; export declare class InMemoryGatewayDatasetObjectStore implements GatewayDatasetObjectStore { private readonly options; private readonly objects; constructor(options?: { now?: () => Date; }); putObject(input: GatewayDatasetObjectPutInput): Promise; readObject(ref: CodaliStorageObjectRef): Promise; listObjects(): CodaliStorageObjectRef[]; } export declare const createInMemoryGatewayDatasetObjectStore: (options?: { now?: () => Date; }) => InMemoryGatewayDatasetObjectStore; export declare class InMemoryGatewayDatasetStore implements GatewayDatasetStore { private readonly records; private readonly batches; private readonly idempotency; collect(input: GatewayDatasetStoreCollectInput): Promise; listRecords(): CodaliStorageDatasetRecord[]; readRecord(recordId: string): CodaliStorageDatasetRecord | undefined; listBatches(): Array<{ idempotencyKey?: string; scope: GatewayDatasetStorageScope; recordIds: string[]; metadata?: Record; }>; } export declare const createInMemoryGatewayDatasetStore: () => InMemoryGatewayDatasetStore; export declare class LocalJsonlGatewayDatasetObjectStore implements GatewayDatasetObjectStore { private readonly options; constructor(options: LocalJsonlGatewayDatasetObjectStoreOptions); putObject(input: GatewayDatasetObjectPutInput): Promise; readObject(ref: CodaliStorageObjectRef): Promise; } export declare const createLocalJsonlGatewayDatasetObjectStore: (options: LocalJsonlGatewayDatasetObjectStoreOptions) => LocalJsonlGatewayDatasetObjectStore; export declare class LocalJsonlGatewayDatasetStore implements GatewayDatasetStore { private readonly options; private readonly idempotency; constructor(options: LocalJsonlGatewayDatasetStoreOptions); collect(input: GatewayDatasetStoreCollectInput): Promise; } export declare const createLocalJsonlGatewayDatasetStore: (options: LocalJsonlGatewayDatasetStoreOptions) => LocalJsonlGatewayDatasetStore; export declare class GatewayDatasetServiceClient implements GatewayDatasetStore { private readonly options; private readonly fetchImpl; constructor(options: GatewayDatasetServiceClientOptions); collect(input: GatewayDatasetStoreCollectInput): Promise; private writeBatch; private fetchWithTimeout; } export declare const createGatewayDatasetServiceClient: (options: GatewayDatasetServiceClientOptions) => GatewayDatasetServiceClient; type GatewayDatasetCollectorBuildInput = Omit; export declare class GatewayDatasetCollector { buildCollectInput(input: GatewayDatasetCollectorBuildInput): Promise; private buildRunRecord; private buildFinalAnswerRecord; private buildRagRetrievalRecord; private buildToolDecisionRecord; private buildEvidenceItemRecord; private buildContextPackRecord; private buildArtifactRecord; private buildPolicyEventRecord; private buildModelCallRecord; private buildSchemaFailureRecord; private buildGoldTargetRecord; } export declare const createGatewayDatasetCollector: () => GatewayDatasetCollector; export declare const buildGatewayDatasetCollectInputFromGatewayResult: (input: Omit) => Promise; export declare const collectGatewayDatasetResult: (input: GatewayDatasetGatewayCollectionInput) => Promise; export declare const collectGatewayDatasetResultNonBlocking: (input: GatewayDatasetGatewayCollectionInput) => GatewayDatasetStoreWriteResult; export {}; //# sourceMappingURL=GatewayDatasetStore.d.ts.map