@mate-academy/prompt-client 1.0.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 (54) hide show
  1. package/README.md +251 -0
  2. package/dist/LLMPromptClient.constants.d.ts +2 -0
  3. package/dist/LLMPromptClient.constants.js +5 -0
  4. package/dist/LLMPromptClient.errors.d.ts +11 -0
  5. package/dist/LLMPromptClient.errors.js +26 -0
  6. package/dist/LLMPromptClient.typedefs.d.ts +22 -0
  7. package/dist/LLMPromptClient.typedefs.js +7 -0
  8. package/dist/LLMTracer.errors.d.ts +4 -0
  9. package/dist/LLMTracer.errors.js +11 -0
  10. package/dist/LLMTracer.typedefs.d.ts +45 -0
  11. package/dist/LLMTracer.typedefs.js +2 -0
  12. package/dist/PromptManagement.constants.d.ts +4 -0
  13. package/dist/PromptManagement.constants.js +10 -0
  14. package/dist/PromptManagement.factory.d.ts +2 -0
  15. package/dist/PromptManagement.factory.js +10 -0
  16. package/dist/PromptManagement.typedefs.d.ts +35 -0
  17. package/dist/PromptManagement.typedefs.js +8 -0
  18. package/dist/index.d.ts +14 -0
  19. package/dist/index.js +30 -0
  20. package/dist/providers/InMemory/InMemory.factory.d.ts +4 -0
  21. package/dist/providers/InMemory/InMemory.factory.js +19 -0
  22. package/dist/providers/InMemory/InMemory.typedefs.d.ts +26 -0
  23. package/dist/providers/InMemory/InMemory.typedefs.js +8 -0
  24. package/dist/providers/InMemory/InMemoryPrompt.client.d.ts +13 -0
  25. package/dist/providers/InMemory/InMemoryPrompt.client.js +61 -0
  26. package/dist/providers/InMemory/InMemoryTracer.client.d.ts +15 -0
  27. package/dist/providers/InMemory/InMemoryTracer.client.js +63 -0
  28. package/dist/providers/Langfuse/Langfuse.factory.d.ts +4 -0
  29. package/dist/providers/Langfuse/Langfuse.factory.js +23 -0
  30. package/dist/providers/Langfuse/Langfuse.helpers.d.ts +1 -0
  31. package/dist/providers/Langfuse/Langfuse.helpers.js +16 -0
  32. package/dist/providers/Langfuse/Langfuse.typedefs.d.ts +14 -0
  33. package/dist/providers/Langfuse/Langfuse.typedefs.js +2 -0
  34. package/dist/providers/Langfuse/LangfusePrompt.client.d.ts +16 -0
  35. package/dist/providers/Langfuse/LangfusePrompt.client.js +81 -0
  36. package/dist/providers/Langfuse/LangfusePrompt.d.ts +13 -0
  37. package/dist/providers/Langfuse/LangfusePrompt.js +29 -0
  38. package/dist/providers/Langfuse/LangfuseTracer.client.d.ts +13 -0
  39. package/dist/providers/Langfuse/LangfuseTracer.client.js +49 -0
  40. package/dist/utilities/index.d.ts +3 -0
  41. package/dist/utilities/index.js +19 -0
  42. package/dist/utilities/logger/PromptManagementLogger.d.ts +7 -0
  43. package/dist/utilities/logger/PromptManagementLogger.js +8 -0
  44. package/dist/utilities/logger/index.d.ts +1 -0
  45. package/dist/utilities/logger/index.js +17 -0
  46. package/dist/utilities/template/compileTemplateVariables.d.ts +1 -0
  47. package/dist/utilities/template/compileTemplateVariables.js +7 -0
  48. package/dist/utilities/template/index.d.ts +1 -0
  49. package/dist/utilities/template/index.js +17 -0
  50. package/dist/utilities/usageDetails/index.d.ts +1 -0
  51. package/dist/utilities/usageDetails/index.js +17 -0
  52. package/dist/utilities/usageDetails/usageDetails.helpers.d.ts +17 -0
  53. package/dist/utilities/usageDetails/usageDetails.helpers.js +33 -0
  54. package/package.json +69 -0
@@ -0,0 +1,15 @@
1
+ import { type LLMGeneration, type LLMGenerationOptions, type LLMTrace, type LLMTraceOptions, type LLMTracer } from '../../LLMTracer.typedefs';
2
+ import { type InMemoryRecordedGeneration, type InMemoryRecordedTrace } from '../../providers/InMemory/InMemory.typedefs';
3
+ export declare class InMemoryTracer implements LLMTracer {
4
+ readonly traces: InMemoryRecordedTrace[];
5
+ readonly generations: InMemoryRecordedGeneration[];
6
+ flushCallCount: number;
7
+ shutdownCallCount: number;
8
+ private nextEntityNumber;
9
+ createTrace(options: LLMTraceOptions): LLMTrace;
10
+ createGeneration(trace: LLMTrace, options: LLMGenerationOptions): LLMGeneration;
11
+ flush(): Promise<void>;
12
+ shutdown(): Promise<void>;
13
+ reset(): void;
14
+ private takeEntityNumber;
15
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InMemoryTracer = void 0;
4
+ class InMemoryTracer {
5
+ constructor() {
6
+ this.traces = [];
7
+ this.generations = [];
8
+ this.flushCallCount = 0;
9
+ this.shutdownCallCount = 0;
10
+ this.nextEntityNumber = 1;
11
+ }
12
+ createTrace(options) {
13
+ const recordedTrace = {
14
+ id: `trace-${this.takeEntityNumber()}`,
15
+ options,
16
+ updates: [],
17
+ };
18
+ this.traces.push(recordedTrace);
19
+ return {
20
+ id: recordedTrace.id,
21
+ getTraceUrl: () => `in-memory://traces/${recordedTrace.id}`,
22
+ update: (updateOptions) => {
23
+ recordedTrace.updates.push(updateOptions);
24
+ },
25
+ };
26
+ }
27
+ createGeneration(trace, options) {
28
+ const recordedGeneration = {
29
+ id: `generation-${this.takeEntityNumber()}`,
30
+ traceId: trace.id,
31
+ options,
32
+ endOptions: null,
33
+ isEnded: false,
34
+ };
35
+ this.generations.push(recordedGeneration);
36
+ return {
37
+ id: recordedGeneration.id,
38
+ end: (endOptions) => {
39
+ recordedGeneration.endOptions = endOptions ?? null;
40
+ recordedGeneration.isEnded = true;
41
+ },
42
+ };
43
+ }
44
+ async flush() {
45
+ this.flushCallCount += 1;
46
+ }
47
+ async shutdown() {
48
+ this.shutdownCallCount += 1;
49
+ }
50
+ reset() {
51
+ this.traces.splice(0);
52
+ this.generations.splice(0);
53
+ this.flushCallCount = 0;
54
+ this.shutdownCallCount = 0;
55
+ this.nextEntityNumber = 1;
56
+ }
57
+ takeEntityNumber() {
58
+ const entityNumber = this.nextEntityNumber;
59
+ this.nextEntityNumber += 1;
60
+ return entityNumber;
61
+ }
62
+ }
63
+ exports.InMemoryTracer = InMemoryTracer;
@@ -0,0 +1,4 @@
1
+ import { type PromptManagementBundle } from '../../PromptManagement.typedefs';
2
+ import { type LangfuseProviderOptions } from '../../providers/Langfuse/Langfuse.typedefs';
3
+ import { type PromptManagementLogger } from '../../utilities/logger';
4
+ export declare const createLangfusePromptManagement: (options: LangfuseProviderOptions, logger: PromptManagementLogger) => PromptManagementBundle;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLangfusePromptManagement = void 0;
4
+ const langfuse_1 = require("langfuse");
5
+ const LangfusePrompt_client_1 = require("../../providers/Langfuse/LangfusePrompt.client");
6
+ const LangfuseTracer_client_1 = require("../../providers/Langfuse/LangfuseTracer.client");
7
+ const createLangfusePromptManagement = (options, logger) => {
8
+ const client = new langfuse_1.Langfuse({
9
+ publicKey: options.credentials.publicKey,
10
+ secretKey: options.credentials.secretKey,
11
+ baseUrl: options.credentials.baseUrl,
12
+ requestTimeout: options.fetchTimeoutMs,
13
+ flushAt: options.flushAt,
14
+ flushInterval: options.flushIntervalMs,
15
+ });
16
+ return {
17
+ promptClient: new LangfusePrompt_client_1.LangfusePromptClient(client, options, logger),
18
+ tracer: new LangfuseTracer_client_1.LangfuseTracer(client, logger),
19
+ flush: () => client.flushAsync(),
20
+ shutdown: () => client.shutdownAsync(),
21
+ };
22
+ };
23
+ exports.createLangfusePromptManagement = createLangfusePromptManagement;
@@ -0,0 +1 @@
1
+ export declare const isLangfuseInfraError: (error: unknown) => boolean;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLangfuseInfraError = void 0;
4
+ const LANGFUSE_INFRA_ERROR_NAMES = [
5
+ 'LangfuseFetchHttpError',
6
+ 'LangfuseFetchNetworkError',
7
+ ];
8
+ const isLangfuseInfraError = (error) => {
9
+ if (typeof error !== 'object' || error === null || !('name' in error)) {
10
+ return false;
11
+ }
12
+ const errorName = error.name;
13
+ return typeof errorName === 'string'
14
+ && LANGFUSE_INFRA_ERROR_NAMES.includes(errorName);
15
+ };
16
+ exports.isLangfuseInfraError = isLangfuseInfraError;
@@ -0,0 +1,14 @@
1
+ export interface LangfuseCredentials {
2
+ publicKey: string;
3
+ secretKey: string;
4
+ baseUrl: string;
5
+ }
6
+ export interface LangfuseProviderOptions {
7
+ credentials: LangfuseCredentials;
8
+ defaultPromptLabel?: string;
9
+ defaultCacheTtlSeconds?: number;
10
+ fetchTimeoutMs?: number;
11
+ maxRetries?: number;
12
+ flushAt?: number;
13
+ flushIntervalMs?: number;
14
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,16 @@
1
+ import { type Langfuse } from 'langfuse';
2
+ import { type GetPromptOptions, type LLMPrompt, type LLMPromptClient } from '../../LLMPromptClient.typedefs';
3
+ import { type LangfuseProviderOptions } from '../../providers/Langfuse/Langfuse.typedefs';
4
+ import { type PromptManagementLogger } from '../../utilities/logger';
5
+ export declare class LangfusePromptClient implements LLMPromptClient {
6
+ private readonly client;
7
+ private readonly providerOptions;
8
+ private readonly logger;
9
+ constructor(client: Langfuse, providerOptions: LangfuseProviderOptions, logger: PromptManagementLogger);
10
+ getPrompt(name: string, options?: GetPromptOptions): Promise<LLMPrompt>;
11
+ shutdown(): Promise<void>;
12
+ private fetchPrompt;
13
+ private resolveLabelOption;
14
+ private ensureTextPrompt;
15
+ private reportPromptResolution;
16
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LangfusePromptClient = void 0;
4
+ const LLMPromptClient_constants_1 = require("../../LLMPromptClient.constants");
5
+ const LLMPromptClient_errors_1 = require("../../LLMPromptClient.errors");
6
+ const Langfuse_helpers_1 = require("../../providers/Langfuse/Langfuse.helpers");
7
+ const LangfusePrompt_1 = require("../../providers/Langfuse/LangfusePrompt");
8
+ const LANGFUSE_TEXT_PROMPT_TYPE = 'text';
9
+ class LangfusePromptClient {
10
+ constructor(client, providerOptions, logger) {
11
+ this.client = client;
12
+ this.providerOptions = providerOptions;
13
+ this.logger = logger;
14
+ }
15
+ async getPrompt(name, options) {
16
+ const nativePrompt = await this.fetchPrompt(name, options);
17
+ this.ensureTextPrompt(name, nativePrompt);
18
+ this.reportPromptResolution(name, nativePrompt);
19
+ return new LangfusePrompt_1.LangfusePrompt(nativePrompt);
20
+ }
21
+ shutdown() {
22
+ return this.client.shutdownAsync();
23
+ }
24
+ async fetchPrompt(name, options) {
25
+ try {
26
+ const nativePrompt = await this.client.getPrompt(name, options?.version, {
27
+ ...this.resolveLabelOption(options),
28
+ cacheTtlSeconds: options?.cacheTtlSeconds
29
+ ?? this.providerOptions.defaultCacheTtlSeconds
30
+ ?? LLMPromptClient_constants_1.DEFAULT_PROMPT_CACHE_TTL_SECONDS,
31
+ fallback: options?.fallback,
32
+ maxRetries: this.providerOptions.maxRetries,
33
+ fetchTimeoutMs: this.providerOptions.fetchTimeoutMs,
34
+ type: LANGFUSE_TEXT_PROMPT_TYPE,
35
+ });
36
+ return nativePrompt;
37
+ }
38
+ catch (error) {
39
+ if ((0, Langfuse_helpers_1.isLangfuseInfraError)(error)) {
40
+ this.logger.error('Failed to fetch Langfuse prompt', {
41
+ error,
42
+ promptName: name,
43
+ });
44
+ throw new LLMPromptClient_errors_1.LLMPromptFetchError(name, error);
45
+ }
46
+ throw new LLMPromptClient_errors_1.LLMPromptNotFoundError(name, error);
47
+ }
48
+ }
49
+ resolveLabelOption(options) {
50
+ if (options?.version !== undefined) {
51
+ return {};
52
+ }
53
+ return {
54
+ label: options?.label
55
+ ?? this.providerOptions.defaultPromptLabel
56
+ ?? LLMPromptClient_constants_1.DEFAULT_PROMPT_LABEL,
57
+ };
58
+ }
59
+ ensureTextPrompt(name, nativePrompt) {
60
+ if (nativePrompt.type !== LANGFUSE_TEXT_PROMPT_TYPE) {
61
+ this.logger.error('Langfuse prompt is not a text prompt', {
62
+ promptName: name,
63
+ promptType: nativePrompt.type,
64
+ });
65
+ throw new LLMPromptClient_errors_1.LLMPromptFetchError(name);
66
+ }
67
+ }
68
+ reportPromptResolution(name, nativePrompt) {
69
+ if (nativePrompt.isFallback) {
70
+ this.logger.warn('Langfuse prompt resolved to the provided fallback', {
71
+ promptName: name,
72
+ });
73
+ return;
74
+ }
75
+ this.logger.debug?.('Langfuse prompt resolved', {
76
+ promptName: name,
77
+ promptVersion: nativePrompt.version,
78
+ });
79
+ }
80
+ }
81
+ exports.LangfusePromptClient = LangfusePromptClient;
@@ -0,0 +1,13 @@
1
+ import { type TextPromptClient } from 'langfuse';
2
+ import { LLMPromptTypes, type LLMPrompt } from '../../LLMPromptClient.typedefs';
3
+ export declare class LangfusePrompt implements LLMPrompt {
4
+ readonly nativePrompt: TextPromptClient;
5
+ readonly type = LLMPromptTypes.Text;
6
+ constructor(nativePrompt: TextPromptClient);
7
+ get name(): string;
8
+ get version(): number;
9
+ get prompt(): string;
10
+ get config(): unknown;
11
+ get isFallback(): boolean;
12
+ compile(variables?: Record<string, string>): string;
13
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LangfusePrompt = void 0;
4
+ const LLMPromptClient_typedefs_1 = require("../../LLMPromptClient.typedefs");
5
+ class LangfusePrompt {
6
+ constructor(nativePrompt) {
7
+ this.nativePrompt = nativePrompt;
8
+ this.type = LLMPromptClient_typedefs_1.LLMPromptTypes.Text;
9
+ }
10
+ get name() {
11
+ return this.nativePrompt.name;
12
+ }
13
+ get version() {
14
+ return this.nativePrompt.version;
15
+ }
16
+ get prompt() {
17
+ return this.nativePrompt.prompt;
18
+ }
19
+ get config() {
20
+ return this.nativePrompt.config;
21
+ }
22
+ get isFallback() {
23
+ return this.nativePrompt.isFallback;
24
+ }
25
+ compile(variables) {
26
+ return this.nativePrompt.compile(variables);
27
+ }
28
+ }
29
+ exports.LangfusePrompt = LangfusePrompt;
@@ -0,0 +1,13 @@
1
+ import { type Langfuse } from 'langfuse';
2
+ import { type LLMGeneration, type LLMGenerationOptions, type LLMTrace, type LLMTraceOptions, type LLMTracer } from '../../LLMTracer.typedefs';
3
+ import { type PromptManagementLogger } from '../../utilities/logger';
4
+ export declare class LangfuseTracer implements LLMTracer {
5
+ private readonly client;
6
+ private readonly logger;
7
+ constructor(client: Langfuse, logger: PromptManagementLogger);
8
+ createTrace(options: LLMTraceOptions): LLMTrace;
9
+ createGeneration(trace: LLMTrace, options: LLMGenerationOptions): LLMGeneration;
10
+ flush(): Promise<void>;
11
+ shutdown(): Promise<void>;
12
+ private wrapError;
13
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LangfuseTracer = void 0;
4
+ const LLMTracer_errors_1 = require("../../LLMTracer.errors");
5
+ const LangfusePrompt_1 = require("../../providers/Langfuse/LangfusePrompt");
6
+ class LangfuseTracer {
7
+ constructor(client, logger) {
8
+ this.client = client;
9
+ this.logger = logger;
10
+ }
11
+ createTrace(options) {
12
+ try {
13
+ return this.client.trace(options);
14
+ }
15
+ catch (error) {
16
+ throw this.wrapError('Failed to create Langfuse trace', error, {
17
+ traceName: options.name,
18
+ });
19
+ }
20
+ }
21
+ createGeneration(trace, options) {
22
+ const { prompt, ...generationOptions } = options;
23
+ try {
24
+ return this.client.generation({
25
+ ...generationOptions,
26
+ traceId: trace.id,
27
+ ...(prompt instanceof LangfusePrompt_1.LangfusePrompt
28
+ ? { prompt: prompt.nativePrompt }
29
+ : {}),
30
+ });
31
+ }
32
+ catch (error) {
33
+ throw this.wrapError('Failed to create Langfuse generation', error, {
34
+ generationName: options.name,
35
+ });
36
+ }
37
+ }
38
+ flush() {
39
+ return this.client.flushAsync();
40
+ }
41
+ shutdown() {
42
+ return this.client.shutdownAsync();
43
+ }
44
+ wrapError(message, error, fields) {
45
+ this.logger.error(message, { error, ...fields });
46
+ return new LLMTracer_errors_1.LLMTracerError(message, error);
47
+ }
48
+ }
49
+ exports.LangfuseTracer = LangfuseTracer;
@@ -0,0 +1,3 @@
1
+ export * from '../utilities/logger';
2
+ export * from '../utilities/template';
3
+ export * from '../utilities/usageDetails';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("../utilities/logger"), exports);
18
+ __exportStar(require("../utilities/template"), exports);
19
+ __exportStar(require("../utilities/usageDetails"), exports);
@@ -0,0 +1,7 @@
1
+ export interface PromptManagementLogger {
2
+ info(message: string, meta?: Record<string, unknown>): void;
3
+ warn(message: string, meta?: Record<string, unknown>): void;
4
+ error(message: string, meta?: Record<string, unknown>): void;
5
+ debug?(message: string, meta?: Record<string, unknown>): void;
6
+ }
7
+ export declare const NOOP_PROMPT_MANAGEMENT_LOGGER: PromptManagementLogger;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NOOP_PROMPT_MANAGEMENT_LOGGER = void 0;
4
+ exports.NOOP_PROMPT_MANAGEMENT_LOGGER = {
5
+ info: () => undefined,
6
+ warn: () => undefined,
7
+ error: () => undefined,
8
+ };
@@ -0,0 +1 @@
1
+ export * from '../../utilities/logger/PromptManagementLogger';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("../../utilities/logger/PromptManagementLogger"), exports);
@@ -0,0 +1 @@
1
+ export declare const compileTemplateVariables: (template: string, variables?: Record<string, string>) => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compileTemplateVariables = void 0;
4
+ const compileTemplateVariables = (template, variables) => Object.entries(variables ?? {}).reduce((compiled, [variableName, variableValue]) => compiled
5
+ .split(`{{${variableName}}}`)
6
+ .join(variableValue), template);
7
+ exports.compileTemplateVariables = compileTemplateVariables;
@@ -0,0 +1 @@
1
+ export * from '../../utilities/template/compileTemplateVariables';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("../../utilities/template/compileTemplateVariables"), exports);
@@ -0,0 +1 @@
1
+ export * from '../../utilities/usageDetails/usageDetails.helpers';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("../../utilities/usageDetails/usageDetails.helpers"), exports);
@@ -0,0 +1,17 @@
1
+ export interface LLMUsageInput {
2
+ inputTextTokens?: number;
3
+ outputTextTokens?: number;
4
+ inputAudioTokens?: number;
5
+ outputAudioTokens?: number;
6
+ inputCachedTextTokens?: number;
7
+ inputCachedAudioTokens?: number;
8
+ outputReasoningTokens?: number;
9
+ }
10
+ export interface LLMCostInput {
11
+ input: number;
12
+ output: number;
13
+ total: number;
14
+ currency: string;
15
+ }
16
+ export declare const usageToUsageDetails: (usage?: LLMUsageInput) => Record<string, number> | undefined;
17
+ export declare const costToCostDetails: (cost?: LLMCostInput) => Record<string, number> | undefined;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.costToCostDetails = exports.usageToUsageDetails = void 0;
4
+ const toPositiveDetails = (keyedAmounts) => {
5
+ const populated = keyedAmounts.filter(([, amount]) => amount > 0);
6
+ if (populated.length === 0) {
7
+ return undefined;
8
+ }
9
+ return Object.fromEntries(populated);
10
+ };
11
+ const usageToUsageDetails = (usage) => {
12
+ if (!usage) {
13
+ return undefined;
14
+ }
15
+ return toPositiveDetails([
16
+ ['input', usage.inputTextTokens ?? 0],
17
+ ['input_cached', usage.inputCachedTextTokens ?? 0],
18
+ ['output', (usage.outputTextTokens ?? 0) + (usage.outputReasoningTokens ?? 0)],
19
+ ['input_audio', usage.inputAudioTokens ?? 0],
20
+ ['output_audio', usage.outputAudioTokens ?? 0],
21
+ ]);
22
+ };
23
+ exports.usageToUsageDetails = usageToUsageDetails;
24
+ const costToCostDetails = (cost) => {
25
+ if (!cost) {
26
+ return undefined;
27
+ }
28
+ return toPositiveDetails([
29
+ ['input', cost.input],
30
+ ['output', cost.output],
31
+ ]);
32
+ };
33
+ exports.costToCostDetails = costToCostDetails;
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@mate-academy/prompt-client",
3
+ "version": "1.0.0",
4
+ "description": "Provider-agnostic LLM prompt management and tracing client (Langfuse, InMemory)",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc --project tsconfig.build.json && tsc-alias",
9
+ "build:minify": "npm run build && npm run minify",
10
+ "minify": "find dist -type f -name \"*.js\" -exec terser {} -c -m -o {} \\;",
11
+ "lint": "eslint .",
12
+ "lint:fix": "eslint . --fix",
13
+ "type-check": "tsc --noEmit",
14
+ "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest src/tests/unit",
15
+ "test:integration": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest src/tests/integration --verbose",
16
+ "prepublishOnly": "npm run clean && npm run lint:fix && npm run type-check && npm run test && npm run build",
17
+ "postpublish": "npm run clean",
18
+ "clean": "rm -rf ./dist",
19
+ "patch": "npm version patch && npm publish",
20
+ "minor": "npm version minor && npm publish",
21
+ "major": "npm version major && npm publish",
22
+ "canary": "npm version prerelease --preid=canary && npm publish --tag=canary"
23
+ },
24
+ "keywords": [
25
+ "llm",
26
+ "prompt",
27
+ "langfuse",
28
+ "tracing",
29
+ "mate-academy"
30
+ ],
31
+ "author": "Mate academy developers",
32
+ "license": "MIT",
33
+ "files": [
34
+ "dist/**/*",
35
+ "README.md"
36
+ ],
37
+ "exports": {
38
+ ".": {
39
+ "types": "./dist/index.d.ts",
40
+ "import": "./dist/index.js",
41
+ "require": "./dist/index.js"
42
+ }
43
+ },
44
+ "typesVersions": {
45
+ "*": {
46
+ ".": [
47
+ "dist/index.d.ts"
48
+ ]
49
+ }
50
+ },
51
+ "dependencies": {
52
+ "langfuse": "^3.38.20"
53
+ },
54
+ "devDependencies": {
55
+ "@eslint/js": "^9.36.0",
56
+ "@types/jest": "^30.0.0",
57
+ "@typescript-eslint/eslint-plugin": "^8.44.1",
58
+ "dotenv": "^17.2.3",
59
+ "eslint": "^9.36.0",
60
+ "eslint-plugin-no-only-tests": "^3.3.0",
61
+ "globals": "^16.4.0",
62
+ "jest": "^30.2.0",
63
+ "terser": "^5.44.0",
64
+ "ts-jest": "^29.4.5",
65
+ "tsc-alias": "^1.8.16",
66
+ "typescript": "^5.9.2",
67
+ "typescript-eslint": "^8.44.1"
68
+ }
69
+ }