@stackone/olap 1.51.0 → 1.53.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -154,29 +154,37 @@ interface IOlapClient {
154
154
  }>, options?: OlapOptions): Promise<void>;
155
155
  recordUnified(unifiedInput: UnifiedInput, unifiedResult: UnifiedResult, options?: OlapOptions): Promise<void>;
156
156
  recordProvider(providerInput: ProviderInput, providerResult: ProviderResult, options?: OlapOptions): Promise<void>;
157
- getLogs(organizationId: string, projectSecureId: string, query: Query): Promise<QueryResult>;
158
- getActionLogs(organizationId: string, projectSecureId: string, query: ActionsQuery): Promise<ActionsQueryResult>;
159
- getActionLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionLog | undefined>;
160
- getLog(organizationId: string, projectSecureId: string, logId: string): Promise<ActionLog | UnifiedLog | undefined>;
161
- getStepLogs(organizationId: string, projectSecureId: string, query: StepsQuery): Promise<StepsQueryResult>;
162
- getStepLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number): Promise<StepLog | undefined>;
163
- getUnifiedLogs(organizationId: string, projectSecureId: string, query: UnifiedQuery): Promise<UnifiedQueryResult>;
164
- getUnifiedLog(organizationId: string, projectSecureId: string, requestId: string): Promise<UnifiedLog | undefined>;
165
- getProviderLogs(organizationId: string, projectSecureId: string, query: ProviderQuery): Promise<ProviderQueryResult>;
166
- getProviderLog(organizationId: string, projectSecureId: string, requestId: string, id: string): Promise<ProviderLog | undefined>;
157
+ getLogs(organizationId: string, projectSecureId: string, query: Query, engine?: OlapEngine): Promise<QueryResult>;
158
+ getActionLogs(organizationId: string, projectSecureId: string, query: ActionsQuery, engine?: OlapEngine): Promise<ActionsQueryResult>;
159
+ getActionLog(organizationId: string, projectSecureId: string, actionRunId: string, engine?: OlapEngine): Promise<ActionLog | undefined>;
160
+ getLog(organizationId: string, projectSecureId: string, logId: string, engine?: OlapEngine): Promise<ActionLog | UnifiedLog | undefined>;
161
+ getStepLogs(organizationId: string, projectSecureId: string, query: StepsQuery, engine?: OlapEngine): Promise<StepsQueryResult>;
162
+ getStepLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number, engine?: OlapEngine): Promise<StepLog | undefined>;
163
+ getUnifiedLogs(organizationId: string, projectSecureId: string, query: UnifiedQuery, engine?: OlapEngine): Promise<UnifiedQueryResult>;
164
+ getUnifiedLog(organizationId: string, projectSecureId: string, requestId: string, engine?: OlapEngine): Promise<UnifiedLog | undefined>;
165
+ getProviderLogs(organizationId: string, projectSecureId: string, query: ProviderQuery, engine?: OlapEngine): Promise<ProviderQueryResult>;
166
+ getProviderLog(organizationId: string, projectSecureId: string, requestId: string, id: string, engine?: OlapEngine): Promise<ProviderLog | undefined>;
167
167
  getActionAdvancedLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionAdvancedLog | undefined>;
168
168
  getStepAdvancedLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number): Promise<StepAdvancedLog | undefined>;
169
169
  getUnifiedAdvancedLog(organizationId: string, projectSecureId: string, requestId: string): Promise<UnifiedAdvancedLog | undefined>;
170
170
  getProviderAdvancedLog(organizationId: string, projectSecureId: string, requestId: string, id: string): Promise<ProviderAdvancedLog | undefined>;
171
171
  getDefenderLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<DefenderLog | undefined>;
172
- getLogsStatsAggregate(organizationId: string, projectSecureId: string, query: AggregateQuery): Promise<AggregateResult>;
173
- getLogsStatsDimensions(organizationId: string, projectSecureId: string, query: DimensionsQuery): Promise<DimensionsResult>;
174
- getSourceUsage(organizationId: string, projectSecureId: string, query: SourceQuery): Promise<SourceResult>;
172
+ getLogsStatsAggregate(organizationId: string, projectSecureId: string, query: AggregateQuery, engine?: OlapEngine): Promise<AggregateResult>;
173
+ getLogsStatsDimensions(organizationId: string, projectSecureId: string, query: DimensionsQuery, engine?: OlapEngine): Promise<DimensionsResult>;
174
+ getSourceUsage(organizationId: string, projectSecureId: string, query: SourceQuery, engine?: OlapEngine): Promise<SourceResult>;
175
175
  }
176
+ type DefenderDecision = 'block' | 'allow' | 'count';
176
177
  type DefenderContext = {
177
178
  result?: {
179
+ allowed?: boolean;
178
180
  riskLevel: string;
181
+ tier2Decision?: DefenderDecision;
179
182
  tier2Score?: number;
183
+ tier2LatencyMs?: number;
184
+ tier3Decision?: DefenderDecision;
185
+ tier3PromptTokens?: number;
186
+ tier3CompletionTokens?: number;
187
+ tier3LatencyMs?: number;
180
188
  [key: string]: unknown;
181
189
  };
182
190
  [key: string]: unknown;
@@ -332,6 +340,7 @@ declare const LogType: {
332
340
  readonly Provider: "provider";
333
341
  };
334
342
  type LogType = (typeof LogType)[keyof typeof LogType];
343
+ type OlapEngine = 'tinybird' | 'clickhouse';
335
344
  type Query = {
336
345
  organizationId?: string | string[];
337
346
  projectSecureId?: string | string[];
@@ -602,7 +611,14 @@ interface TinybirdConfig {
602
611
  token: string;
603
612
  allowHttp?: boolean;
604
613
  }
605
- interface TinybirdResponse<T> {
614
+ interface ClickHouseConfig {
615
+ url: string;
616
+ username?: string;
617
+ password?: string;
618
+ database: string;
619
+ requestTimeout?: number;
620
+ }
621
+ interface QueryResponse<T> {
606
622
  meta: Array<{
607
623
  name: string;
608
624
  type: string;
@@ -616,13 +632,27 @@ interface TinybirdResponse<T> {
616
632
  bytes_read: number;
617
633
  };
618
634
  }
619
- interface TinybirdQueryOptions<TParams = Record<string, unknown>, TResult = unknown> {
635
+ interface QueryOptions<TParams = Record<string, unknown>, TResult = unknown> {
620
636
  endpoint: string;
621
637
  params?: TParams;
622
638
  schema?: {
623
639
  parse: (data: unknown) => TResult;
624
640
  };
625
641
  }
642
+ interface IQueryClient {
643
+ query<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult>): Promise<TResult[]>;
644
+ queryWithPagination<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult> & {
645
+ pageNumber?: number;
646
+ pageSize?: number;
647
+ }): Promise<{
648
+ data: TResult[];
649
+ total: number;
650
+ pageNumber: number;
651
+ pageSize: number;
652
+ }>;
653
+ queryRaw<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult>): Promise<QueryResponse<TResult[]>>;
654
+ isReady(): boolean;
655
+ }
626
656
  interface ILog {
627
657
  logType: LogType;
628
658
  eventTime: Date;
@@ -666,7 +696,14 @@ type ActionLog = ILog & {
666
696
  success?: boolean;
667
697
  statusCode?: number;
668
698
  riskLevel?: string;
699
+ allowed?: boolean;
700
+ tier2Decision?: string;
669
701
  tier2Score?: number;
702
+ tier2LatencyMs?: number;
703
+ tier3Decision?: string;
704
+ tier3PromptTokens?: number;
705
+ tier3CompletionTokens?: number;
706
+ tier3LatencyMs?: number;
670
707
  advancedExpiresAt?: Date;
671
708
  defenderExpiresAt?: Date;
672
709
  };
@@ -756,6 +793,35 @@ type ProviderLog = ILog & {
756
793
  duration?: number;
757
794
  };
758
795
  //#endregion
796
+ //#region src/logs/clickhouseClient.d.ts
797
+ declare class ClickHouseClient implements IQueryClient {
798
+ #private;
799
+ constructor(config?: ClickHouseConfig, logger?: ILogger);
800
+ query<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult>): Promise<TResult[]>;
801
+ queryWithPagination<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult> & {
802
+ pageNumber?: number;
803
+ pageSize?: number;
804
+ }): Promise<{
805
+ data: TResult[];
806
+ total: number;
807
+ pageNumber: number;
808
+ pageSize: number;
809
+ }>;
810
+ queryRaw<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult>): Promise<QueryResponse<TResult[]>>;
811
+ isReady(): boolean;
812
+ close(): Promise<void>;
813
+ }
814
+ //#endregion
815
+ //#region src/logs/clientFactory.d.ts
816
+ type OlapQueryClientType = 'tinybird' | 'clickhouse';
817
+ interface OlapQueryClientConfig {
818
+ type?: OlapQueryClientType;
819
+ tinybird?: TinybirdConfig;
820
+ clickhouse?: ClickHouseConfig;
821
+ }
822
+ declare function createOlapQueryClient(config: OlapQueryClientConfig, httpClient?: HttpClient, logger?: ILogger): IQueryClient;
823
+ declare function createConfigFromEnv(): OlapQueryClientConfig;
824
+ //#endregion
759
825
  //#region src/datasets/types.d.ts
760
826
  type LogfireConfig = {
761
827
  token?: string;
@@ -788,6 +854,7 @@ declare class OlapClient implements IOlapClient {
788
854
  kafkaClientConfig,
789
855
  s3ClientConfig,
790
856
  tinybirdConfig,
857
+ clickhouseConfig,
791
858
  sinkConfig,
792
859
  logger
793
860
  }?: {
@@ -797,6 +864,7 @@ declare class OlapClient implements IOlapClient {
797
864
  kafkaClientConfig?: KafkaClientConfig;
798
865
  s3ClientConfig?: S3ClientConfig;
799
866
  tinybirdConfig?: TinybirdConfig;
867
+ clickhouseConfig?: ClickHouseConfig;
800
868
  sinkConfig?: OlapSinkConfig;
801
869
  logger?: ILogger;
802
870
  }): Promise<OlapClient>;
@@ -813,24 +881,24 @@ declare class OlapClient implements IOlapClient {
813
881
  }>, options?: OlapOptions): Promise<void>;
814
882
  recordUnified(unifiedInput: UnifiedInput, unifiedResult: UnifiedResult, options?: OlapOptions): Promise<void>;
815
883
  recordProvider(providerInput: ProviderInput, providerResult: ProviderResult, options?: OlapOptions): Promise<void>;
816
- getLogs(organizationId: string, projectSecureId: string, query: Query): Promise<QueryResult>;
817
- getActionLogs(organizationId: string, projectSecureId: string, query: ActionsQuery): Promise<ActionsQueryResult>;
818
- getActionLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionLog | undefined>;
819
- getLog(organizationId: string, projectSecureId: string, logId: string): Promise<ActionLog | UnifiedLog | undefined>;
820
- getStepLogs(organizationId: string, projectSecureId: string, query: StepsQuery): Promise<StepsQueryResult>;
821
- getStepLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number): Promise<StepLog | undefined>;
822
- getUnifiedLogs(organizationId: string, projectSecureId: string, query: UnifiedQuery): Promise<UnifiedQueryResult>;
823
- getUnifiedLog(organizationId: string, projectSecureId: string, requestId: string): Promise<UnifiedLog | undefined>;
824
- getProviderLogs(organizationId: string, projectSecureId: string, query: ProviderQuery): Promise<ProviderQueryResult>;
825
- getProviderLog(organizationId: string, projectSecureId: string, requestId: string, id: string): Promise<ProviderLog | undefined>;
884
+ getLogs(organizationId: string, projectSecureId: string, query: Query, engine?: OlapEngine): Promise<QueryResult>;
885
+ getActionLogs(organizationId: string, projectSecureId: string, query: ActionsQuery, engine?: OlapEngine): Promise<ActionsQueryResult>;
886
+ getActionLog(organizationId: string, projectSecureId: string, actionRunId: string, engine?: OlapEngine): Promise<ActionLog | undefined>;
887
+ getLog(organizationId: string, projectSecureId: string, logId: string, engine?: OlapEngine): Promise<ActionLog | UnifiedLog | undefined>;
888
+ getStepLogs(organizationId: string, projectSecureId: string, query: StepsQuery, engine?: OlapEngine): Promise<StepsQueryResult>;
889
+ getStepLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number, engine?: OlapEngine): Promise<StepLog | undefined>;
890
+ getUnifiedLogs(organizationId: string, projectSecureId: string, query: UnifiedQuery, engine?: OlapEngine): Promise<UnifiedQueryResult>;
891
+ getUnifiedLog(organizationId: string, projectSecureId: string, requestId: string, engine?: OlapEngine): Promise<UnifiedLog | undefined>;
892
+ getProviderLogs(organizationId: string, projectSecureId: string, query: ProviderQuery, engine?: OlapEngine): Promise<ProviderQueryResult>;
893
+ getProviderLog(organizationId: string, projectSecureId: string, requestId: string, id: string, engine?: OlapEngine): Promise<ProviderLog | undefined>;
826
894
  getActionAdvancedLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionAdvancedLog | undefined>;
827
895
  getStepAdvancedLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number): Promise<StepAdvancedLog | undefined>;
828
896
  getUnifiedAdvancedLog(organizationId: string, projectSecureId: string, requestId: string): Promise<UnifiedAdvancedLog | undefined>;
829
897
  getProviderAdvancedLog(organizationId: string, projectSecureId: string, requestId: string, id: string): Promise<ProviderAdvancedLog | undefined>;
830
898
  getDefenderLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<DefenderLog | undefined>;
831
- getLogsStatsAggregate(organizationId: string, projectSecureId: string, query: AggregateQuery): Promise<AggregateResult>;
832
- getLogsStatsDimensions(organizationId: string, projectSecureId: string, query: DimensionsQuery): Promise<DimensionsResult>;
833
- getSourceUsage(organizationId: string, projectSecureId: string, query: SourceQuery): Promise<SourceResult>;
899
+ getLogsStatsAggregate(organizationId: string, projectSecureId: string, query: AggregateQuery, engine?: OlapEngine): Promise<AggregateResult>;
900
+ getLogsStatsDimensions(organizationId: string, projectSecureId: string, query: DimensionsQuery, engine?: OlapEngine): Promise<DimensionsResult>;
901
+ getSourceUsage(organizationId: string, projectSecureId: string, query: SourceQuery, engine?: OlapEngine): Promise<SourceResult>;
834
902
  }
835
903
  //#endregion
836
904
  //#region src/olap/olapClientManager.d.ts
@@ -841,6 +909,7 @@ declare const buildOlapClientInstance: ({
841
909
  kafkaClientConfig,
842
910
  s3ClientConfig,
843
911
  tinybirdConfig,
912
+ clickhouseConfig,
844
913
  sinkConfig,
845
914
  logger
846
915
  }?: {
@@ -850,6 +919,7 @@ declare const buildOlapClientInstance: ({
850
919
  kafkaClientConfig?: KafkaClientConfig;
851
920
  s3ClientConfig?: S3ClientConfig;
852
921
  tinybirdConfig?: TinybirdConfig;
922
+ clickhouseConfig?: ClickHouseConfig;
853
923
  sinkConfig?: OlapSinkConfig;
854
924
  logger?: ILogger;
855
925
  }) => Promise<IOlapClient>;
@@ -862,6 +932,7 @@ declare class OlapClientManager {
862
932
  kafkaClientConfig,
863
933
  s3ClientConfig,
864
934
  tinybirdConfig,
935
+ clickhouseConfig,
865
936
  sinkConfig,
866
937
  logger,
867
938
  getOlapClient
@@ -872,6 +943,7 @@ declare class OlapClientManager {
872
943
  kafkaClientConfig?: KafkaClientConfig;
873
944
  s3ClientConfig?: S3ClientConfig;
874
945
  tinybirdConfig?: TinybirdConfig;
946
+ clickhouseConfig?: ClickHouseConfig;
875
947
  sinkConfig?: OlapSinkConfig;
876
948
  logger?: ILogger;
877
949
  getOlapClient?: typeof buildOlapClientInstance;
@@ -879,4 +951,4 @@ declare class OlapClientManager {
879
951
  static resetInstance(): void;
880
952
  }
881
953
  //#endregion
882
- export { type ActionAdvancedLog, type ActionInput, type ActionLog, type ActionResult, type ActionsQuery, type ActionsQueryResult, type AdvancedOptions, type AdvancedSinkConfig, type AggregateQuery, type AggregateResult, AuthType, type AuthType as AuthTypeValue, type DatasetsOptions, type DatasetsSinkConfig, type DefenderContext, type DefenderLog, type DefenderOptions, type DefenderSinkConfig, Dimension, type Dimension as DimensionValues, type DimensionsQuery, type DimensionsResult, type ILog, type IOlapClient, IntervalType, type IntervalType as IntervalTypeValues, LogType, type LogType as LogTypeValues, type LogfireConfig, type LogsOptions, OlapClient, OlapClientManager, type OlapOptions, type OlapSinkConfig, OrderBy, type OrderBy as OrderByValues, OrderDirection, type OrderDirection as OrderDirectionValues, type ProviderAdvancedLog, type ProviderInput, type ProviderLog, type ProviderQuery, type ProviderQueryResult, type ProviderResult, type Query, type QueryResult, type Source, type SourceQuery, type SourceResult, SourceType, type SourceType as SourceTypeValue, type StepAdvancedLog, type StepInput, type StepLog, type StepResult, type StepsQuery, type StepsQueryResult, StreamType, type StreamType as StreamTypeValue, type TinybirdConfig, type TinybirdQueryOptions, type TinybirdResponse, TransportType, type TransportType as TransportTypeValue, type UnifiedAdvancedLog, type UnifiedInput, type UnifiedLog, type UnifiedQuery, type UnifiedQueryResult, type UnifiedResult };
954
+ export { type ActionAdvancedLog, type ActionInput, type ActionLog, type ActionResult, type ActionsQuery, type ActionsQueryResult, type AdvancedOptions, type AdvancedSinkConfig, type AggregateQuery, type AggregateResult, AuthType, type AuthType as AuthTypeValue, ClickHouseClient, type ClickHouseConfig, type DatasetsOptions, type DatasetsSinkConfig, type DefenderContext, type DefenderLog, type DefenderOptions, type DefenderSinkConfig, Dimension, type Dimension as DimensionValues, type DimensionsQuery, type DimensionsResult, type ILog, type IOlapClient, type IQueryClient, type IQueryClient as ITinybirdClient, IntervalType, type IntervalType as IntervalTypeValues, LogType, type LogType as LogTypeValues, type LogfireConfig, type LogsOptions, OlapClient, OlapClientManager, type OlapEngine, type OlapOptions, type OlapQueryClientConfig, type OlapQueryClientType, type OlapSinkConfig, OrderBy, type OrderBy as OrderByValues, OrderDirection, type OrderDirection as OrderDirectionValues, type ProviderAdvancedLog, type ProviderInput, type ProviderLog, type ProviderQuery, type ProviderQueryResult, type ProviderResult, type Query, type QueryOptions, type QueryOptions as TinybirdQueryOptions, type QueryResponse, type QueryResponse as TinybirdResponse, type QueryResult, type Source, type SourceQuery, type SourceResult, SourceType, type SourceType as SourceTypeValue, type StepAdvancedLog, type StepInput, type StepLog, type StepResult, type StepsQuery, type StepsQueryResult, StreamType, type StreamType as StreamTypeValue, type TinybirdConfig, TransportType, type TransportType as TransportTypeValue, type UnifiedAdvancedLog, type UnifiedInput, type UnifiedLog, type UnifiedQuery, type UnifiedQueryResult, type UnifiedResult, createConfigFromEnv, createOlapQueryClient };
package/dist/index.d.mts CHANGED
@@ -153,29 +153,37 @@ interface IOlapClient {
153
153
  }>, options?: OlapOptions): Promise<void>;
154
154
  recordUnified(unifiedInput: UnifiedInput, unifiedResult: UnifiedResult, options?: OlapOptions): Promise<void>;
155
155
  recordProvider(providerInput: ProviderInput, providerResult: ProviderResult, options?: OlapOptions): Promise<void>;
156
- getLogs(organizationId: string, projectSecureId: string, query: Query): Promise<QueryResult>;
157
- getActionLogs(organizationId: string, projectSecureId: string, query: ActionsQuery): Promise<ActionsQueryResult>;
158
- getActionLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionLog | undefined>;
159
- getLog(organizationId: string, projectSecureId: string, logId: string): Promise<ActionLog | UnifiedLog | undefined>;
160
- getStepLogs(organizationId: string, projectSecureId: string, query: StepsQuery): Promise<StepsQueryResult>;
161
- getStepLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number): Promise<StepLog | undefined>;
162
- getUnifiedLogs(organizationId: string, projectSecureId: string, query: UnifiedQuery): Promise<UnifiedQueryResult>;
163
- getUnifiedLog(organizationId: string, projectSecureId: string, requestId: string): Promise<UnifiedLog | undefined>;
164
- getProviderLogs(organizationId: string, projectSecureId: string, query: ProviderQuery): Promise<ProviderQueryResult>;
165
- getProviderLog(organizationId: string, projectSecureId: string, requestId: string, id: string): Promise<ProviderLog | undefined>;
156
+ getLogs(organizationId: string, projectSecureId: string, query: Query, engine?: OlapEngine): Promise<QueryResult>;
157
+ getActionLogs(organizationId: string, projectSecureId: string, query: ActionsQuery, engine?: OlapEngine): Promise<ActionsQueryResult>;
158
+ getActionLog(organizationId: string, projectSecureId: string, actionRunId: string, engine?: OlapEngine): Promise<ActionLog | undefined>;
159
+ getLog(organizationId: string, projectSecureId: string, logId: string, engine?: OlapEngine): Promise<ActionLog | UnifiedLog | undefined>;
160
+ getStepLogs(organizationId: string, projectSecureId: string, query: StepsQuery, engine?: OlapEngine): Promise<StepsQueryResult>;
161
+ getStepLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number, engine?: OlapEngine): Promise<StepLog | undefined>;
162
+ getUnifiedLogs(organizationId: string, projectSecureId: string, query: UnifiedQuery, engine?: OlapEngine): Promise<UnifiedQueryResult>;
163
+ getUnifiedLog(organizationId: string, projectSecureId: string, requestId: string, engine?: OlapEngine): Promise<UnifiedLog | undefined>;
164
+ getProviderLogs(organizationId: string, projectSecureId: string, query: ProviderQuery, engine?: OlapEngine): Promise<ProviderQueryResult>;
165
+ getProviderLog(organizationId: string, projectSecureId: string, requestId: string, id: string, engine?: OlapEngine): Promise<ProviderLog | undefined>;
166
166
  getActionAdvancedLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionAdvancedLog | undefined>;
167
167
  getStepAdvancedLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number): Promise<StepAdvancedLog | undefined>;
168
168
  getUnifiedAdvancedLog(organizationId: string, projectSecureId: string, requestId: string): Promise<UnifiedAdvancedLog | undefined>;
169
169
  getProviderAdvancedLog(organizationId: string, projectSecureId: string, requestId: string, id: string): Promise<ProviderAdvancedLog | undefined>;
170
170
  getDefenderLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<DefenderLog | undefined>;
171
- getLogsStatsAggregate(organizationId: string, projectSecureId: string, query: AggregateQuery): Promise<AggregateResult>;
172
- getLogsStatsDimensions(organizationId: string, projectSecureId: string, query: DimensionsQuery): Promise<DimensionsResult>;
173
- getSourceUsage(organizationId: string, projectSecureId: string, query: SourceQuery): Promise<SourceResult>;
171
+ getLogsStatsAggregate(organizationId: string, projectSecureId: string, query: AggregateQuery, engine?: OlapEngine): Promise<AggregateResult>;
172
+ getLogsStatsDimensions(organizationId: string, projectSecureId: string, query: DimensionsQuery, engine?: OlapEngine): Promise<DimensionsResult>;
173
+ getSourceUsage(organizationId: string, projectSecureId: string, query: SourceQuery, engine?: OlapEngine): Promise<SourceResult>;
174
174
  }
175
+ type DefenderDecision = 'block' | 'allow' | 'count';
175
176
  type DefenderContext = {
176
177
  result?: {
178
+ allowed?: boolean;
177
179
  riskLevel: string;
180
+ tier2Decision?: DefenderDecision;
178
181
  tier2Score?: number;
182
+ tier2LatencyMs?: number;
183
+ tier3Decision?: DefenderDecision;
184
+ tier3PromptTokens?: number;
185
+ tier3CompletionTokens?: number;
186
+ tier3LatencyMs?: number;
179
187
  [key: string]: unknown;
180
188
  };
181
189
  [key: string]: unknown;
@@ -331,6 +339,7 @@ declare const LogType: {
331
339
  readonly Provider: "provider";
332
340
  };
333
341
  type LogType = (typeof LogType)[keyof typeof LogType];
342
+ type OlapEngine = 'tinybird' | 'clickhouse';
334
343
  type Query = {
335
344
  organizationId?: string | string[];
336
345
  projectSecureId?: string | string[];
@@ -601,7 +610,14 @@ interface TinybirdConfig {
601
610
  token: string;
602
611
  allowHttp?: boolean;
603
612
  }
604
- interface TinybirdResponse<T> {
613
+ interface ClickHouseConfig {
614
+ url: string;
615
+ username?: string;
616
+ password?: string;
617
+ database: string;
618
+ requestTimeout?: number;
619
+ }
620
+ interface QueryResponse<T> {
605
621
  meta: Array<{
606
622
  name: string;
607
623
  type: string;
@@ -615,13 +631,27 @@ interface TinybirdResponse<T> {
615
631
  bytes_read: number;
616
632
  };
617
633
  }
618
- interface TinybirdQueryOptions<TParams = Record<string, unknown>, TResult = unknown> {
634
+ interface QueryOptions<TParams = Record<string, unknown>, TResult = unknown> {
619
635
  endpoint: string;
620
636
  params?: TParams;
621
637
  schema?: {
622
638
  parse: (data: unknown) => TResult;
623
639
  };
624
640
  }
641
+ interface IQueryClient {
642
+ query<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult>): Promise<TResult[]>;
643
+ queryWithPagination<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult> & {
644
+ pageNumber?: number;
645
+ pageSize?: number;
646
+ }): Promise<{
647
+ data: TResult[];
648
+ total: number;
649
+ pageNumber: number;
650
+ pageSize: number;
651
+ }>;
652
+ queryRaw<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult>): Promise<QueryResponse<TResult[]>>;
653
+ isReady(): boolean;
654
+ }
625
655
  interface ILog {
626
656
  logType: LogType;
627
657
  eventTime: Date;
@@ -665,7 +695,14 @@ type ActionLog = ILog & {
665
695
  success?: boolean;
666
696
  statusCode?: number;
667
697
  riskLevel?: string;
698
+ allowed?: boolean;
699
+ tier2Decision?: string;
668
700
  tier2Score?: number;
701
+ tier2LatencyMs?: number;
702
+ tier3Decision?: string;
703
+ tier3PromptTokens?: number;
704
+ tier3CompletionTokens?: number;
705
+ tier3LatencyMs?: number;
669
706
  advancedExpiresAt?: Date;
670
707
  defenderExpiresAt?: Date;
671
708
  };
@@ -755,6 +792,35 @@ type ProviderLog = ILog & {
755
792
  duration?: number;
756
793
  };
757
794
  //#endregion
795
+ //#region src/logs/clickhouseClient.d.ts
796
+ declare class ClickHouseClient implements IQueryClient {
797
+ #private;
798
+ constructor(config?: ClickHouseConfig, logger?: ILogger);
799
+ query<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult>): Promise<TResult[]>;
800
+ queryWithPagination<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult> & {
801
+ pageNumber?: number;
802
+ pageSize?: number;
803
+ }): Promise<{
804
+ data: TResult[];
805
+ total: number;
806
+ pageNumber: number;
807
+ pageSize: number;
808
+ }>;
809
+ queryRaw<TParams = Record<string, unknown>, TResult = unknown>(options: QueryOptions<TParams, TResult>): Promise<QueryResponse<TResult[]>>;
810
+ isReady(): boolean;
811
+ close(): Promise<void>;
812
+ }
813
+ //#endregion
814
+ //#region src/logs/clientFactory.d.ts
815
+ type OlapQueryClientType = 'tinybird' | 'clickhouse';
816
+ interface OlapQueryClientConfig {
817
+ type?: OlapQueryClientType;
818
+ tinybird?: TinybirdConfig;
819
+ clickhouse?: ClickHouseConfig;
820
+ }
821
+ declare function createOlapQueryClient(config: OlapQueryClientConfig, httpClient?: HttpClient, logger?: ILogger): IQueryClient;
822
+ declare function createConfigFromEnv(): OlapQueryClientConfig;
823
+ //#endregion
758
824
  //#region src/datasets/types.d.ts
759
825
  type LogfireConfig = {
760
826
  token?: string;
@@ -787,6 +853,7 @@ declare class OlapClient implements IOlapClient {
787
853
  kafkaClientConfig,
788
854
  s3ClientConfig,
789
855
  tinybirdConfig,
856
+ clickhouseConfig,
790
857
  sinkConfig,
791
858
  logger
792
859
  }?: {
@@ -796,6 +863,7 @@ declare class OlapClient implements IOlapClient {
796
863
  kafkaClientConfig?: KafkaClientConfig;
797
864
  s3ClientConfig?: S3ClientConfig;
798
865
  tinybirdConfig?: TinybirdConfig;
866
+ clickhouseConfig?: ClickHouseConfig;
799
867
  sinkConfig?: OlapSinkConfig;
800
868
  logger?: ILogger;
801
869
  }): Promise<OlapClient>;
@@ -812,24 +880,24 @@ declare class OlapClient implements IOlapClient {
812
880
  }>, options?: OlapOptions): Promise<void>;
813
881
  recordUnified(unifiedInput: UnifiedInput, unifiedResult: UnifiedResult, options?: OlapOptions): Promise<void>;
814
882
  recordProvider(providerInput: ProviderInput, providerResult: ProviderResult, options?: OlapOptions): Promise<void>;
815
- getLogs(organizationId: string, projectSecureId: string, query: Query): Promise<QueryResult>;
816
- getActionLogs(organizationId: string, projectSecureId: string, query: ActionsQuery): Promise<ActionsQueryResult>;
817
- getActionLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionLog | undefined>;
818
- getLog(organizationId: string, projectSecureId: string, logId: string): Promise<ActionLog | UnifiedLog | undefined>;
819
- getStepLogs(organizationId: string, projectSecureId: string, query: StepsQuery): Promise<StepsQueryResult>;
820
- getStepLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number): Promise<StepLog | undefined>;
821
- getUnifiedLogs(organizationId: string, projectSecureId: string, query: UnifiedQuery): Promise<UnifiedQueryResult>;
822
- getUnifiedLog(organizationId: string, projectSecureId: string, requestId: string): Promise<UnifiedLog | undefined>;
823
- getProviderLogs(organizationId: string, projectSecureId: string, query: ProviderQuery): Promise<ProviderQueryResult>;
824
- getProviderLog(organizationId: string, projectSecureId: string, requestId: string, id: string): Promise<ProviderLog | undefined>;
883
+ getLogs(organizationId: string, projectSecureId: string, query: Query, engine?: OlapEngine): Promise<QueryResult>;
884
+ getActionLogs(organizationId: string, projectSecureId: string, query: ActionsQuery, engine?: OlapEngine): Promise<ActionsQueryResult>;
885
+ getActionLog(organizationId: string, projectSecureId: string, actionRunId: string, engine?: OlapEngine): Promise<ActionLog | undefined>;
886
+ getLog(organizationId: string, projectSecureId: string, logId: string, engine?: OlapEngine): Promise<ActionLog | UnifiedLog | undefined>;
887
+ getStepLogs(organizationId: string, projectSecureId: string, query: StepsQuery, engine?: OlapEngine): Promise<StepsQueryResult>;
888
+ getStepLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number, engine?: OlapEngine): Promise<StepLog | undefined>;
889
+ getUnifiedLogs(organizationId: string, projectSecureId: string, query: UnifiedQuery, engine?: OlapEngine): Promise<UnifiedQueryResult>;
890
+ getUnifiedLog(organizationId: string, projectSecureId: string, requestId: string, engine?: OlapEngine): Promise<UnifiedLog | undefined>;
891
+ getProviderLogs(organizationId: string, projectSecureId: string, query: ProviderQuery, engine?: OlapEngine): Promise<ProviderQueryResult>;
892
+ getProviderLog(organizationId: string, projectSecureId: string, requestId: string, id: string, engine?: OlapEngine): Promise<ProviderLog | undefined>;
825
893
  getActionAdvancedLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<ActionAdvancedLog | undefined>;
826
894
  getStepAdvancedLog(organizationId: string, projectSecureId: string, actionRunId: string, stepIndex: number): Promise<StepAdvancedLog | undefined>;
827
895
  getUnifiedAdvancedLog(organizationId: string, projectSecureId: string, requestId: string): Promise<UnifiedAdvancedLog | undefined>;
828
896
  getProviderAdvancedLog(organizationId: string, projectSecureId: string, requestId: string, id: string): Promise<ProviderAdvancedLog | undefined>;
829
897
  getDefenderLog(organizationId: string, projectSecureId: string, actionRunId: string): Promise<DefenderLog | undefined>;
830
- getLogsStatsAggregate(organizationId: string, projectSecureId: string, query: AggregateQuery): Promise<AggregateResult>;
831
- getLogsStatsDimensions(organizationId: string, projectSecureId: string, query: DimensionsQuery): Promise<DimensionsResult>;
832
- getSourceUsage(organizationId: string, projectSecureId: string, query: SourceQuery): Promise<SourceResult>;
898
+ getLogsStatsAggregate(organizationId: string, projectSecureId: string, query: AggregateQuery, engine?: OlapEngine): Promise<AggregateResult>;
899
+ getLogsStatsDimensions(organizationId: string, projectSecureId: string, query: DimensionsQuery, engine?: OlapEngine): Promise<DimensionsResult>;
900
+ getSourceUsage(organizationId: string, projectSecureId: string, query: SourceQuery, engine?: OlapEngine): Promise<SourceResult>;
833
901
  }
834
902
  //#endregion
835
903
  //#region src/olap/olapClientManager.d.ts
@@ -840,6 +908,7 @@ declare const buildOlapClientInstance: ({
840
908
  kafkaClientConfig,
841
909
  s3ClientConfig,
842
910
  tinybirdConfig,
911
+ clickhouseConfig,
843
912
  sinkConfig,
844
913
  logger
845
914
  }?: {
@@ -849,6 +918,7 @@ declare const buildOlapClientInstance: ({
849
918
  kafkaClientConfig?: KafkaClientConfig;
850
919
  s3ClientConfig?: S3ClientConfig;
851
920
  tinybirdConfig?: TinybirdConfig;
921
+ clickhouseConfig?: ClickHouseConfig;
852
922
  sinkConfig?: OlapSinkConfig;
853
923
  logger?: ILogger;
854
924
  }) => Promise<IOlapClient>;
@@ -861,6 +931,7 @@ declare class OlapClientManager {
861
931
  kafkaClientConfig,
862
932
  s3ClientConfig,
863
933
  tinybirdConfig,
934
+ clickhouseConfig,
864
935
  sinkConfig,
865
936
  logger,
866
937
  getOlapClient
@@ -871,6 +942,7 @@ declare class OlapClientManager {
871
942
  kafkaClientConfig?: KafkaClientConfig;
872
943
  s3ClientConfig?: S3ClientConfig;
873
944
  tinybirdConfig?: TinybirdConfig;
945
+ clickhouseConfig?: ClickHouseConfig;
874
946
  sinkConfig?: OlapSinkConfig;
875
947
  logger?: ILogger;
876
948
  getOlapClient?: typeof buildOlapClientInstance;
@@ -878,4 +950,4 @@ declare class OlapClientManager {
878
950
  static resetInstance(): void;
879
951
  }
880
952
  //#endregion
881
- export { type ActionAdvancedLog, type ActionInput, type ActionLog, type ActionResult, type ActionsQuery, type ActionsQueryResult, type AdvancedOptions, type AdvancedSinkConfig, type AggregateQuery, type AggregateResult, AuthType, type AuthType as AuthTypeValue, type DatasetsOptions, type DatasetsSinkConfig, type DefenderContext, type DefenderLog, type DefenderOptions, type DefenderSinkConfig, Dimension, type Dimension as DimensionValues, type DimensionsQuery, type DimensionsResult, type ILog, type IOlapClient, IntervalType, type IntervalType as IntervalTypeValues, LogType, type LogType as LogTypeValues, type LogfireConfig, type LogsOptions, OlapClient, OlapClientManager, type OlapOptions, type OlapSinkConfig, OrderBy, type OrderBy as OrderByValues, OrderDirection, type OrderDirection as OrderDirectionValues, type ProviderAdvancedLog, type ProviderInput, type ProviderLog, type ProviderQuery, type ProviderQueryResult, type ProviderResult, type Query, type QueryResult, type Source, type SourceQuery, type SourceResult, SourceType, type SourceType as SourceTypeValue, type StepAdvancedLog, type StepInput, type StepLog, type StepResult, type StepsQuery, type StepsQueryResult, StreamType, type StreamType as StreamTypeValue, type TinybirdConfig, type TinybirdQueryOptions, type TinybirdResponse, TransportType, type TransportType as TransportTypeValue, type UnifiedAdvancedLog, type UnifiedInput, type UnifiedLog, type UnifiedQuery, type UnifiedQueryResult, type UnifiedResult };
953
+ export { type ActionAdvancedLog, type ActionInput, type ActionLog, type ActionResult, type ActionsQuery, type ActionsQueryResult, type AdvancedOptions, type AdvancedSinkConfig, type AggregateQuery, type AggregateResult, AuthType, type AuthType as AuthTypeValue, ClickHouseClient, type ClickHouseConfig, type DatasetsOptions, type DatasetsSinkConfig, type DefenderContext, type DefenderLog, type DefenderOptions, type DefenderSinkConfig, Dimension, type Dimension as DimensionValues, type DimensionsQuery, type DimensionsResult, type ILog, type IOlapClient, type IQueryClient, type IQueryClient as ITinybirdClient, IntervalType, type IntervalType as IntervalTypeValues, LogType, type LogType as LogTypeValues, type LogfireConfig, type LogsOptions, OlapClient, OlapClientManager, type OlapEngine, type OlapOptions, type OlapQueryClientConfig, type OlapQueryClientType, type OlapSinkConfig, OrderBy, type OrderBy as OrderByValues, OrderDirection, type OrderDirection as OrderDirectionValues, type ProviderAdvancedLog, type ProviderInput, type ProviderLog, type ProviderQuery, type ProviderQueryResult, type ProviderResult, type Query, type QueryOptions, type QueryOptions as TinybirdQueryOptions, type QueryResponse, type QueryResponse as TinybirdResponse, type QueryResult, type Source, type SourceQuery, type SourceResult, SourceType, type SourceType as SourceTypeValue, type StepAdvancedLog, type StepInput, type StepLog, type StepResult, type StepsQuery, type StepsQueryResult, StreamType, type StreamType as StreamTypeValue, type TinybirdConfig, TransportType, type TransportType as TransportTypeValue, type UnifiedAdvancedLog, type UnifiedInput, type UnifiedLog, type UnifiedQuery, type UnifiedQueryResult, type UnifiedResult, createConfigFromEnv, createOlapQueryClient };