airbyte-faros-destination 0.23.21 → 0.23.22

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.
@@ -0,0 +1,34 @@
1
+ import { AirbyteRecord } from 'faros-airbyte-cdk';
2
+ import { Converter, DestinationRecord, StreamContext } from '../converter';
3
+ export declare const AI_ACCOUNT_MODEL = "ai_Account";
4
+ export declare const AI_PROJECT_MODEL = "ai_Project";
5
+ export declare const AI_PRINCIPAL_MODEL = "ai_Principal";
6
+ export declare const AI_CREDENTIAL_MODEL = "ai_Credential";
7
+ export declare const AI_USAGE_MODEL = "ai_Usage";
8
+ export declare const AI_COST_MODEL = "ai_Cost";
9
+ export interface AIAccountKey {
10
+ uid: string;
11
+ source: string;
12
+ }
13
+ export interface AIAccountEntityKey {
14
+ uid: string;
15
+ account: AIAccountKey;
16
+ }
17
+ interface AIDimensions {
18
+ account: AIAccountKey;
19
+ project: AIAccountEntityKey | null;
20
+ projectName?: string | null;
21
+ principal?: AIAccountEntityKey | null;
22
+ principalEmail?: string | null;
23
+ credential: AIAccountEntityKey | null;
24
+ }
25
+ export declare abstract class OpenAIPlatformConverter extends Converter {
26
+ readonly source = "OpenAI_Platform";
27
+ private readonly seenDimensions;
28
+ id(record: AirbyteRecord): any;
29
+ protected account(ctx: StreamContext): AIAccountKey;
30
+ protected accountEntity(uid: string | null | undefined, account: AIAccountKey): AIAccountEntityKey | null;
31
+ protected destinationDimensionRecord(uid: string, destinationRecord: DestinationRecord): DestinationRecord | null;
32
+ protected destinationDimensions({ account, project, projectName, principal, principalEmail, credential, }: AIDimensions): DestinationRecord[];
33
+ }
34
+ export {};
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenAIPlatformConverter = exports.AI_COST_MODEL = exports.AI_USAGE_MODEL = exports.AI_CREDENTIAL_MODEL = exports.AI_PRINCIPAL_MODEL = exports.AI_PROJECT_MODEL = exports.AI_ACCOUNT_MODEL = void 0;
4
+ const converter_1 = require("../converter");
5
+ exports.AI_ACCOUNT_MODEL = 'ai_Account';
6
+ exports.AI_PROJECT_MODEL = 'ai_Project';
7
+ exports.AI_PRINCIPAL_MODEL = 'ai_Principal';
8
+ exports.AI_CREDENTIAL_MODEL = 'ai_Credential';
9
+ exports.AI_USAGE_MODEL = 'ai_Usage';
10
+ exports.AI_COST_MODEL = 'ai_Cost';
11
+ class OpenAIPlatformConverter extends converter_1.Converter {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.source = 'OpenAI_Platform';
15
+ this.seenDimensions = new Set();
16
+ }
17
+ id(record) {
18
+ return record?.record?.data?._record_id;
19
+ }
20
+ account(ctx) {
21
+ return {
22
+ uid: ctx.getSourceConfig().organization_id,
23
+ source: this.source,
24
+ };
25
+ }
26
+ accountEntity(uid, account) {
27
+ return uid ? { uid, account } : null;
28
+ }
29
+ destinationDimensionRecord(uid, destinationRecord) {
30
+ const { model } = destinationRecord;
31
+ const key = `${model}:${uid}`;
32
+ if (this.seenDimensions.has(key))
33
+ return null;
34
+ this.seenDimensions.add(key);
35
+ return destinationRecord;
36
+ }
37
+ destinationDimensions({ account, project, projectName, principal, principalEmail, credential, }) {
38
+ const result = [];
39
+ const accountRecord = this.destinationDimensionRecord(account.uid, {
40
+ model: exports.AI_ACCOUNT_MODEL,
41
+ record: account,
42
+ });
43
+ if (accountRecord)
44
+ result.push(accountRecord);
45
+ if (project) {
46
+ const projectRecord = this.destinationDimensionRecord(project.uid, {
47
+ model: exports.AI_PROJECT_MODEL,
48
+ record: { ...project, name: projectName ?? null },
49
+ });
50
+ if (projectRecord)
51
+ result.push(projectRecord);
52
+ }
53
+ if (principal) {
54
+ const principalRecord = this.destinationDimensionRecord(principal.uid, {
55
+ model: exports.AI_PRINCIPAL_MODEL,
56
+ record: { ...principal, email: principalEmail ?? null },
57
+ });
58
+ if (principalRecord)
59
+ result.push(principalRecord);
60
+ }
61
+ if (credential) {
62
+ const credentialRecord = this.destinationDimensionRecord(credential.uid, {
63
+ model: exports.AI_CREDENTIAL_MODEL,
64
+ record: { ...credential },
65
+ });
66
+ if (credentialRecord)
67
+ result.push(credentialRecord);
68
+ }
69
+ return result;
70
+ }
71
+ }
72
+ exports.OpenAIPlatformConverter = OpenAIPlatformConverter;
73
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/converters/openai-platform/common.ts"],"names":[],"mappings":";;;AAEA,4CAAyE;AAE5D,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAChC,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAChC,QAAA,kBAAkB,GAAG,cAAc,CAAC;AACpC,QAAA,mBAAmB,GAAG,eAAe,CAAC;AACtC,QAAA,cAAc,GAAG,UAAU,CAAC;AAC5B,QAAA,aAAa,GAAG,SAAS,CAAC;AAqBvC,MAAsB,uBAAwB,SAAQ,qBAAS;IAA/D;;QACW,WAAM,GAAG,iBAAiB,CAAC;QACnB,mBAAc,GAAG,IAAI,GAAG,EAAU,CAAC;IAqEtD,CAAC;IAnEC,EAAE,CAAC,MAAqB;QACtB,OAAO,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,CAAC;IAC1C,CAAC;IAES,OAAO,CAAC,GAAkB;QAClC,OAAO;YACL,GAAG,EAAE,GAAG,CAAC,eAAe,EAAE,CAAC,eAAe;YAC1C,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAC;IACJ,CAAC;IAES,aAAa,CACrB,GAA8B,EAC9B,OAAqB;QAErB,OAAO,GAAG,CAAC,CAAC,CAAC,EAAC,GAAG,EAAE,OAAO,EAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrC,CAAC;IAES,0BAA0B,CAClC,GAAW,EACX,iBAAoC;QAEpC,MAAM,EAAC,KAAK,EAAC,GAAG,iBAAiB,CAAC;QAClC,MAAM,GAAG,GAAG,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC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GAAG,EAAE;gBACvE,KAAK,EAAE,2BAAmB;gBAC1B,MAAM,EAAE,EAAC,GAAG,UAAU,EAAC;aACxB,CAAC,CAAC;YACH,IAAI,gBAAgB;gBAAE,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAvED,0DAuEC"}
@@ -0,0 +1,26 @@
1
+ import { AirbyteRecord } from 'faros-airbyte-cdk';
2
+ import { DestinationModel, DestinationRecord, StreamContext } from '../converter';
3
+ import { OpenAIPlatformConverter } from './common';
4
+ export interface OpenAICompletionsUsageItem {
5
+ _record_id: string;
6
+ start_time: number;
7
+ end_time: number;
8
+ project_id?: string | null;
9
+ project_name?: string | null;
10
+ user_id?: string | null;
11
+ principal_email?: string | null;
12
+ api_key_id?: string | null;
13
+ model?: string | null;
14
+ batch?: boolean | null;
15
+ service_tier?: string | null;
16
+ num_model_requests?: number | null;
17
+ input_tokens?: number | null;
18
+ input_cached_tokens?: number | null;
19
+ input_cache_write_tokens?: number | null;
20
+ input_uncached_tokens?: number | null;
21
+ output_tokens?: number | null;
22
+ }
23
+ export declare class CompletionsUsage extends OpenAIPlatformConverter {
24
+ readonly destinationModels: ReadonlyArray<DestinationModel>;
25
+ convert(record: AirbyteRecord, ctx: StreamContext): Promise<ReadonlyArray<DestinationRecord>>;
26
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CompletionsUsage = void 0;
4
+ const faros_js_client_1 = require("faros-js-client");
5
+ const common_1 = require("./common");
6
+ class CompletionsUsage extends common_1.OpenAIPlatformConverter {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.destinationModels = [
10
+ common_1.AI_ACCOUNT_MODEL,
11
+ common_1.AI_PROJECT_MODEL,
12
+ common_1.AI_PRINCIPAL_MODEL,
13
+ common_1.AI_CREDENTIAL_MODEL,
14
+ common_1.AI_USAGE_MODEL,
15
+ ];
16
+ }
17
+ async convert(record, ctx) {
18
+ const item = record.record.data;
19
+ const account = this.account(ctx);
20
+ const project = this.accountEntity(item.project_id, account);
21
+ const principal = this.accountEntity(item.user_id, account);
22
+ const credential = this.accountEntity(item.api_key_id, account);
23
+ const result = this.destinationDimensions({
24
+ account,
25
+ project,
26
+ projectName: item.project_name,
27
+ principal,
28
+ principalEmail: item.principal_email,
29
+ credential,
30
+ });
31
+ result.push({
32
+ model: common_1.AI_USAGE_MODEL,
33
+ record: {
34
+ uid: item._record_id,
35
+ source: this.source,
36
+ account,
37
+ project,
38
+ principal,
39
+ credential,
40
+ startedAt: faros_js_client_1.Utils.toDate(item.start_time * 1000),
41
+ endedAt: faros_js_client_1.Utils.toDate(item.end_time * 1000),
42
+ model: item.model ?? null,
43
+ batch: item.batch ?? null,
44
+ serviceTier: item.service_tier ?? null,
45
+ requests: item.num_model_requests ?? null,
46
+ // OpenAI input_tokens is the inclusive total. The following cached,
47
+ // cache-write, and uncached counters are its components.
48
+ inputTokens: item.input_tokens ?? null,
49
+ cachedInputTokens: item.input_cached_tokens ?? null,
50
+ cacheWriteInputTokens: item.input_cache_write_tokens ?? null,
51
+ uncachedInputTokens: item.input_uncached_tokens ?? null,
52
+ outputTokens: item.output_tokens ?? null,
53
+ },
54
+ });
55
+ return result;
56
+ }
57
+ }
58
+ exports.CompletionsUsage = CompletionsUsage;
59
+ //# sourceMappingURL=completions_usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"completions_usage.js","sourceRoot":"","sources":["../../../src/converters/openai-platform/completions_usage.ts"],"names":[],"mappings":";;;AACA,qDAAsC;AAGtC,qCAOkB;AAsBlB,MAAa,gBAAiB,SAAQ,gCAAuB;IAA7D;;QACW,sBAAiB,GAAoC;YAC5D,yBAAgB;YAChB,yBAAgB;YAChB,2BAAkB;YAClB,4BAAmB;YACnB,uBAAc;SACf,CAAC;IA8CJ,CAAC;IA5CC,KAAK,CAAC,OAAO,CACX,MAAqB,EACrB,GAAk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ACtC,iBAAiB,EAAE,IAAI,CAAC,mBAAmB,IAAI,IAAI;gBACnD,qBAAqB,EAAE,IAAI,CAAC,wBAAwB,IAAI,IAAI;gBAC5D,mBAAmB,EAAE,IAAI,CAAC,qBAAqB,IAAI,IAAI;gBACvD,YAAY,EAAE,IAAI,CAAC,aAAa,IAAI,IAAI;aACzC;SACF,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AArDD,4CAqDC"}
@@ -0,0 +1,20 @@
1
+ import { AirbyteRecord } from 'faros-airbyte-cdk';
2
+ import { DestinationModel, DestinationRecord, StreamContext } from '../converter';
3
+ import { OpenAIPlatformConverter } from './common';
4
+ export interface OpenAICostItem {
5
+ _record_id: string;
6
+ start_time: number;
7
+ end_time: number;
8
+ project_id?: string | null;
9
+ project_name?: string | null;
10
+ api_key_id?: string | null;
11
+ line_item?: string | null;
12
+ amount?: number | null;
13
+ currency?: string | null;
14
+ quantity?: number | null;
15
+ quantity_unit?: string | null;
16
+ }
17
+ export declare class Costs extends OpenAIPlatformConverter {
18
+ readonly destinationModels: ReadonlyArray<DestinationModel>;
19
+ convert(record: AirbyteRecord, ctx: StreamContext): Promise<ReadonlyArray<DestinationRecord>>;
20
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Costs = void 0;
4
+ const faros_js_client_1 = require("faros-js-client");
5
+ const common_1 = require("./common");
6
+ class Costs extends common_1.OpenAIPlatformConverter {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.destinationModels = [
10
+ common_1.AI_ACCOUNT_MODEL,
11
+ common_1.AI_PROJECT_MODEL,
12
+ common_1.AI_CREDENTIAL_MODEL,
13
+ common_1.AI_COST_MODEL,
14
+ ];
15
+ }
16
+ async convert(record, ctx) {
17
+ const item = record.record.data;
18
+ const account = this.account(ctx);
19
+ const project = this.accountEntity(item.project_id, account);
20
+ const credential = this.accountEntity(item.api_key_id, account);
21
+ const result = this.destinationDimensions({
22
+ account,
23
+ project,
24
+ projectName: item.project_name,
25
+ credential,
26
+ });
27
+ result.push({
28
+ model: common_1.AI_COST_MODEL,
29
+ record: {
30
+ uid: item._record_id,
31
+ source: this.source,
32
+ account,
33
+ project,
34
+ credential,
35
+ startedAt: faros_js_client_1.Utils.toDate(item.start_time * 1000),
36
+ endedAt: faros_js_client_1.Utils.toDate(item.end_time * 1000),
37
+ lineItem: item.line_item ?? null,
38
+ model: null,
39
+ amount: item.amount ?? null,
40
+ currency: item.currency ?? null,
41
+ quantity: item.quantity ?? null,
42
+ quantityUnit: item.quantity_unit ?? null,
43
+ },
44
+ });
45
+ return result;
46
+ }
47
+ }
48
+ exports.Costs = Costs;
49
+ //# sourceMappingURL=costs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"costs.js","sourceRoot":"","sources":["../../../src/converters/openai-platform/costs.ts"],"names":[],"mappings":";;;AACA,qDAAsC;AAGtC,qCAMkB;AAgBlB,MAAa,KAAM,SAAQ,gCAAuB;IAAlD;;QACW,sBAAiB,GAAoC;YAC5D,yBAAgB;YAChB,yBAAgB;YAChB,4BAAmB;YACnB,sBAAa;SACd,CAAC;IAqCJ,CAAC;IAnCC,KAAK,CAAC,OAAO,CACX,MAAqB,EACrB,GAAkB;QAElB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAsB,CAAC;QAClD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAClC,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAC7D,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAChE,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC;YACxC,OAAO;YACP,OAAO;YACP,WAAW,EAAE,IAAI,CAAC,YAAY;YAC9B,UAAU;SACX,CAAC,C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