@sisense/sdk-ai-core 0.5.0 → 0.6.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.
Files changed (37) hide show
  1. package/dist/constants.d.ts +7 -0
  2. package/dist/constants.d.ts.map +1 -1
  3. package/dist/engines/build-query/build-query-engine.d.ts +11 -0
  4. package/dist/engines/build-query/build-query-engine.d.ts.map +1 -0
  5. package/dist/engines/build-query/index.d.ts +3 -0
  6. package/dist/engines/build-query/index.d.ts.map +1 -0
  7. package/dist/engines/build-query/types.d.ts +34 -0
  8. package/dist/engines/build-query/types.d.ts.map +1 -0
  9. package/dist/engines/chart-builder/chart-builder-engine.d.ts +4 -3
  10. package/dist/engines/chart-builder/chart-builder-engine.d.ts.map +1 -1
  11. package/dist/engines/chart-builder/create-chart/create-chart.d.ts +3 -2
  12. package/dist/engines/chart-builder/create-chart/create-chart.d.ts.map +1 -1
  13. package/dist/engines/chart-builder/create-chart/generate-chart-table.d.ts +2 -1
  14. package/dist/engines/chart-builder/create-chart/generate-chart-table.d.ts.map +1 -1
  15. package/dist/engines/chart-builder/types.d.ts +46 -18
  16. package/dist/engines/chart-builder/types.d.ts.map +1 -1
  17. package/dist/engines/chart-builder/update-chart/chart-options-schemas.d.ts +218 -218
  18. package/dist/engines/chart-builder/update-chart/schemas.d.ts +24 -24
  19. package/dist/engines/data-source-fields/data-source-fields-engine.d.ts +7 -6
  20. package/dist/engines/data-source-fields/data-source-fields-engine.d.ts.map +1 -1
  21. package/dist/engines/data-source-fields/types.d.ts +1 -43
  22. package/dist/engines/data-source-fields/types.d.ts.map +1 -1
  23. package/dist/engines/index.d.ts +1 -0
  24. package/dist/engines/index.d.ts.map +1 -1
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +4606 -2136
  28. package/dist/index.js.map +1 -1
  29. package/dist/services/llm/llm-consumption-service.d.ts +17 -0
  30. package/dist/services/llm/llm-consumption-service.d.ts.map +1 -0
  31. package/dist/utils/create-custom-fetch.d.ts +10 -0
  32. package/dist/utils/create-custom-fetch.d.ts.map +1 -0
  33. package/dist/utils/http-client.d.ts +2 -5
  34. package/dist/utils/http-client.d.ts.map +1 -1
  35. package/dist/utils/user-action-tracking.d.ts +17 -26
  36. package/dist/utils/user-action-tracking.d.ts.map +1 -1
  37. package/package.json +2 -1
@@ -0,0 +1,17 @@
1
+ export declare class QuotaExceededError extends Error {
2
+ constructor(message?: string);
3
+ }
4
+ /**
5
+ * Captures consumption of LLM tokens.
6
+ * @param requestOptions - Optional request options (e.g. from withTrackingHeaders()) for user-action tracking headers.
7
+ * @returns The capture UUID if successful, undefined otherwise.
8
+ */
9
+ export declare function captureConsumption(requestOptions?: RequestInit): Promise<string | undefined>;
10
+ /**
11
+ * Reports consumption of LLM tokens to the backend.
12
+ * Fire-and-forget: failures are non-critical and are silently ignored.
13
+ * @param quotaId - The capture UUID from captureConsumption.
14
+ * @param requestOptions - Optional request options (e.g. from withTrackingHeaders()) for user-action tracking headers.
15
+ */
16
+ export declare function reportConsumption(quotaId: string, requestOptions?: RequestInit): void;
17
+ //# sourceMappingURL=llm-consumption-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-consumption-service.d.ts","sourceRoot":"","sources":["../../../src/services/llm/llm-consumption-service.ts"],"names":[],"mappings":"AAMA,qBAAa,kBAAmB,SAAQ,KAAK;gBAChC,OAAO,SAAmB;CAItC;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACvC,cAAc,CAAC,EAAE,WAAW,GAC1B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CA+B7B;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAChC,OAAO,EAAE,MAAM,EACf,cAAc,CAAC,EAAE,WAAW,GAC1B,IAAI,CAQN"}
@@ -0,0 +1,10 @@
1
+ import { HttpClient } from '@sisense/sdk-rest-client';
2
+ /**
3
+ * Factory function to create a custom fetch function for OpenAI chat completions
4
+ * This fetch function applies authentication headers from the provided httpClient
5
+ * and sets the user action tracking headers.
6
+ * @param httpClient - The HTTP client instance to use for authentication
7
+ * @returns Custom fetch function
8
+ */
9
+ export declare function createCustomFetch(httpClient: HttpClient): (url: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
10
+ //# sourceMappingURL=create-custom-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-custom-fetch.d.ts","sourceRoot":"","sources":["../../src/utils/create-custom-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAItD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,UAAU,IAEtD,KAAK,WAAW,GAAG,GAAG,EACtB,OAAO,WAAW,KAChB,OAAO,CAAC,QAAQ,CAAC,CA+BpB"}
@@ -24,10 +24,7 @@ export declare function createHttpClientFromAuthenticator(url: string, authentic
24
24
  */
25
25
  export declare function createHttpClientFromConfig(config: AuthenticatorConfig): HttpClient;
26
26
  /**
27
- * Factory function to create a custom fetch function for OpenAI chat completions
28
- * This fetch function applies authentication headers from the provided httpClient
29
- * @param httpClient - The HTTP client instance to use for authentication
30
- * @returns Custom fetch function
27
+ * Extracts HTTP status code from various error shapes (Axios, fetch, custom).
31
28
  */
32
- export declare function createCustomFetch(httpClient: HttpClient): (url: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
29
+ export declare function getHttpErrorStatus(error: unknown): number | undefined;
33
30
  //# sourceMappingURL=http-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../../src/utils/http-client.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EAEb,UAAU,EACV,MAAM,0BAA0B,CAAC;AAUlC,MAAM,MAAM,mBAAmB,GAAG;IACjC,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CA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AAU,CAYZ;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,mBAAmB,GACzB,UAAU,CAQZ;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOrE"}
@@ -1,33 +1,24 @@
1
- /**
2
- * User Action Tracking Utility
3
- *
4
- * Provides functionality for generating user action IDs and W3C traceparent headers
5
- * to enable end-to-end trace visibility across the Assistant, ai-integration, and LLM services.
6
- *
7
- * The client generates valid W3C traceparent headers which ai-integration (server-side)
8
- * uses to create/continue traces in Langfuse. No Langfuse keys are needed on the client.
9
- */
10
- export declare const USER_ACTION_ID_HEADER = "x-user-action-id";
11
- export declare const TRACEPARENT_HEADER = "traceparent";
1
+ import { HEADER_FEATURE_NAME, HEADER_INTERFACE_NAME, HEADER_QUOTA_ID, HEADER_TRACEPARENT, HEADER_USER_ACTION_ID } from '../constants';
12
2
  export declare function generateUserActionId(): string;
13
3
  export declare function generateTraceparent(): string;
14
4
  export interface UserActionHeaders extends Record<string, string> {
15
- [USER_ACTION_ID_HEADER]: string;
16
- [TRACEPARENT_HEADER]: string;
17
- }
18
- declare class UserActionContext {
19
- private currentActionId;
20
- private currentTraceparent;
21
- startAction(): UserActionHeaders;
22
- getHeaders(): UserActionHeaders;
23
- endAction(): void;
24
- hasActiveAction(): boolean;
25
- getCurrentActionId(): string | null;
5
+ [HEADER_USER_ACTION_ID]: string;
6
+ [HEADER_TRACEPARENT]: string;
7
+ [HEADER_INTERFACE_NAME]: string;
8
+ [HEADER_FEATURE_NAME]: string;
9
+ [HEADER_QUOTA_ID]: string;
26
10
  }
27
- export declare const userActionContext: UserActionContext;
28
- export declare function startUserAction(): UserActionHeaders;
11
+ export declare const startUserAction: (interfaceName?: string, featureName?: string) => Promise<UserActionHeaders>;
29
12
  export declare function getUserActionHeaders(): UserActionHeaders;
30
13
  export declare function withTrackingHeaders(options?: RequestInit): RequestInit;
31
- export declare function endUserAction(): void;
32
- export {};
14
+ export declare const endUserAction: () => void;
15
+ /**
16
+ * Wraps an async function with user-action tracking (capture at start, report at end).
17
+ * Use for standalone engine calls (e.g., from MCP Server) when tracing and consumption tracking are required.
18
+ * @param interfaceName - e.g. 'MCP'
19
+ * @param featureName - e.g. 'BUILD-CHART'
20
+ * @param fn - The async function to execute
21
+ * @returns The result of fn
22
+ */
23
+ export declare function runWithUserAction<T>(interfaceName: string, featureName: string, fn: () => Promise<T>): Promise<T>;
33
24
  //# sourceMappingURL=user-action-tracking.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-action-tracking.d.ts","sourceRoot":"","sources":["../../src/utils/user-action-tracking.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AACxD,eAAO,MAAM,kBAAkB,gBAAgB,CAAC;AAEhD,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAM5C;AAED,MAAM,WAAW,iBAAkB,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAChE,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAChC,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,cAAM,iBAAiB;IACtB,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,kBAAkB,CAAuB;IAEjD,WAAW,IAAI,iBAAiB;IAMhC,UAAU,IAAI,iBAAiB;IAW/B,SAAS,IAAI,IAAI;IAKjB,eAAe,IAAI,OAAO;IAI1B,kBAAkB,IAAI,MAAM,GAAG,IAAI;CAGnC;AAED,eAAO,MAAM,iBAAiB,mBAA0B,CAAC;AAEzD,wBAAgB,eAAe,IAAI,iBAAiB,CAEnD;AAED,wBAAgB,oBAAoB,IAAI,iBAAiB,CAExD;AAiCD,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,WAAgB,GAAG,WAAW,CAW1E;AAED,wBAAgB,aAAa,IAAI,IAAI,CAEpC"}
1
+ {"version":3,"file":"user-action-tracking.d.ts","sourceRoot":"","sources":["../../src/utils/user-action-tracking.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,qBAAqB,EACrB,MAAM,aAAa,CAAC;AAOrB,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AAED,wBAAgB,mBAAmB,IAAI,MAAM,CAM5C;AAED,MAAM,WAAW,iBAAkB,SAAQ,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAChE,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAChC,CAAC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC7B,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAChC,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC9B,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAwED,eAAO,MAAM,eAAe,GAAI,gBAAgB,MAAM,EAAE,cAAc,MAAM,+BAClB,CAAC;AAE3D,wBAAgB,oBAAoB,IAAI,iBAAiB,CAExD;AAiCD,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,WAAgB,GAAG,WAAW,CAY1E;AAED,eAAO,MAAM,aAAa,YAAsC,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,CAAC,EACxC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAClB,OAAO,CAAC,CAAC,CAAC,CAWZ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sisense/sdk-ai-core",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "main": "./dist/index.js",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",
@@ -30,6 +30,7 @@
30
30
  "nanoid": "^5.0.9",
31
31
  "openai": "^4.86.1",
32
32
  "tslib": "^2.8.1",
33
+ "yaml": "^2.8.2",
33
34
  "zod": "^3.24.1",
34
35
  "zod-to-json-schema": "^3.24.1"
35
36
  },