@lyxa.ai/core 1.4.289 → 1.4.290

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.
@@ -1,7 +1,6 @@
1
1
  import { LLMProvider } from '../llm-provider-service';
2
2
  export interface IAICompletionProvider {
3
- generateSearchVariants(items: ItemTextInput[], model?: string, instructions?: string, options?: {
4
- concurrency?: number;
3
+ generateSearchVariantsBatch(items: ItemTextInput[], model?: string, instructions?: string, options?: {
5
4
  pollIntervalMs?: number;
6
5
  maxWaitMs?: number;
7
6
  }): Promise<TextVariantResult[]>;
@@ -18,7 +17,6 @@ export interface AiConfiguration {
18
17
  model?: string;
19
18
  instructions?: string;
20
19
  prompt?: string;
21
- concurrency?: number;
22
20
  }
23
21
  export interface ItemTextInput {
24
22
  itemId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"common-llm-interfaces.js","sourceRoot":"/","sources":["libraries/llm/interfaces/common-llm-interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import { LLMProvider } from '../llm-provider-service';\n\nexport interface IAICompletionProvider {\n\tgenerateSearchVariants(\n\t\titems: ItemTextInput[],\n\t\tmodel?: string,\n\t\tinstructions?: string,\n\t\toptions?: { concurrency?: number; pollIntervalMs?: number; maxWaitMs?: number }\n\t): Promise<TextVariantResult[]>;\n}\n\n// export interface TextVariantConfig {\n// \tisArabic?: boolean; // Arabic translation, Arabic script\n// \tisArabizi?: boolean; // Arabic word, Latin script (e.g. \"zaytoon\")\n// \tisArabicTransliteration?: boolean; // original word, spelled phonetically in Arabic script (e.g. \"أوليف\")\n// }\n\nexport interface TextVariantResult {\n\titemId: string;\n\toriginal: string;\n\tarabic?: string[];\n\tarabizi?: string[];\n\tarabicTransliteration?: string[];\n}\n\nexport interface AiConfiguration {\n\tprovider: LLMProvider;\n\tmodel?: string;\n\tinstructions?: string;\n\tprompt?: string;\n\tconcurrency?: number;\n}\n\nexport interface ItemTextInput {\n\titemId: string;\n\ttext: string;\n}\n"]}
1
+ {"version":3,"file":"common-llm-interfaces.js","sourceRoot":"/","sources":["libraries/llm/interfaces/common-llm-interfaces.ts"],"names":[],"mappings":"","sourcesContent":["import { LLMProvider } from '../llm-provider-service';\n\nexport interface IAICompletionProvider {\n\tgenerateSearchVariantsBatch(\n\t\titems: ItemTextInput[],\n\t\tmodel?: string,\n\t\tinstructions?: string,\n\t\toptions?: { pollIntervalMs?: number; maxWaitMs?: number }\n\t): Promise<TextVariantResult[]>;\n}\n\n// export interface TextVariantConfig {\n// \tisArabic?: boolean; // Arabic translation, Arabic script\n// \tisArabizi?: boolean; // Arabic word, Latin script (e.g. \"zaytoon\")\n// \tisArabicTransliteration?: boolean; // original word, spelled phonetically in Arabic script (e.g. \"أوليف\")\n// }\n\nexport interface TextVariantResult {\n\titemId: string;\n\toriginal: string;\n\tarabic?: string[];\n\tarabizi?: string[];\n\tarabicTransliteration?: string[];\n}\n\nexport interface AiConfiguration {\n\tprovider: LLMProvider;\n\tmodel?: string;\n\tinstructions?: string;\n\tprompt?: string;\n}\n\nexport interface ItemTextInput {\n\titemId: string;\n\ttext: string;\n}"]}
@@ -8,6 +8,6 @@ export declare class LLMCompletionService {
8
8
  private providerInstance;
9
9
  private readonly factories;
10
10
  constructor(provider: LLMProvider);
11
- generatePromptVariants(payload: ItemTextInput[], aiConfigurations: AiConfiguration): Promise<TextVariantResult[]>;
11
+ generateSearchVariants(payload: ItemTextInput[], aiConfigurations: AiConfiguration): Promise<TextVariantResult[]>;
12
12
  private getProvider;
13
13
  }
@@ -27,19 +27,16 @@ class LLMCompletionService {
27
27
  constructor(provider) {
28
28
  this.provider = provider;
29
29
  }
30
- async generatePromptVariants(payload, aiConfigurations) {
30
+ async generateSearchVariants(payload, aiConfigurations) {
31
31
  const provider = await this.getProvider();
32
32
  console.log(`You are using llm provider: ${this.provider} with model: ${aiConfigurations.model ?? 'gpt-5-mini'}`);
33
- const options = {
34
- concurrency: aiConfigurations.concurrency ?? 10,
35
- };
36
- return provider.generateSearchVariants(payload, aiConfigurations.model, aiConfigurations.instructions, options);
33
+ return provider.generateSearchVariantsBatch(payload, aiConfigurations.model, aiConfigurations.instructions);
37
34
  }
38
35
  async getProvider() {
39
36
  if (!this.providerInstance) {
40
37
  const factory = this.factories[this.provider];
41
38
  if (!factory) {
42
- throw (0, error_common_1.badRequestError)(`Unsupported transliteration provider: ${this.provider}`);
39
+ throw (0, error_common_1.badRequestError)(`Unsupported LLM provider: ${this.provider}`);
43
40
  }
44
41
  this.providerInstance = await factory();
45
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"llm-provider-service.js","sourceRoot":"/","sources":["libraries/llm/llm-provider-service.ts"],"names":[],"mappings":";;;AAAA,6BAAqC;AAOrC,+DAA+D;AAC/D,iEAAuE;AAEvE,IAAY,WAGX;AAHD,WAAY,WAAW;IACtB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;AAClB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAID,MAAa,oBAAoB;IAgBH;IAfrB,gBAAgB,GAAiC,IAAI,CAAC;IAE7C,SAAS,GAAyC;QAClE,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE;YAChC,MAAM,MAAM,GAAG,MAAM,IAAA,gBAAY,GAAE,CAAC,iBAAiB,EAAE,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;YACjF,IAAI,CAAC,MAAM,EAAE,CAAC;gBACb,MAAM,IAAA,8BAAe,EAAC,iCAAiC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC;YAC9E,CAAC;YACD,OAAO,IAAI,0CAAwB,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;QAC3D,CAAC;QACD,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE;YAChC,MAAM,IAAA,8BAAe,EAAC,YAAY,WAAW,CAAC,MAAM,yBAAyB,CAAC,CAAC;QAChF,CAAC;KACD,CAAC;IAEF,YAA6B,QAAqB;QAArB,aAAQ,GAAR,QAAQ,CAAa;IAAG,CAAC;IAEtD,KAAK,CAAC,sBAAsB,CAC3B,OAAwB,EACxB,gBAAiC;QAEjC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAC1C,OAAO,CAAC,GAAG,CACV,+BAA+B,IAAI,CAAC,QAAQ,gBAAgB,gBAAgB,CAAC,KAAK,IAAI,YAAY,EAAE,CACpG,CAAC;QACF,MAAM,OAAO,GAAG;YACf,WAAW,EAAE,gBAAgB,CAAC,WAAW,IAAI,EAAE;SAC/C,CAAC;QACF,OAAO,QAAQ,CAAC,sBAAsB,CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,EAAE,gBAAgB,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACjH,CAAC;IAEO,KAAK,CAAC,WAAW;QACxB,IAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC9C,IAAI,CAAC,OAAO,EAAE,CAAC;gBACd,MAAM,IAAA,8BAAe,EAAC,yCAAyC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YACjF,CAAC;YACD,IAAI,CAAC,gBAAgB,GAAG,MAAM,OAAO,EAAE,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC9B,CAAC;CACD;AA1CD,oDA0CC","sourcesContent":["import { getLibraries } from '../..';\nimport {\n\tItemTextInput,\n\tAiConfiguration,\n\tTextVariantResult,\n\tIAICompletionProvider,\n} from './interfaces/common-llm-interfaces';\nimport { badRequestError } from '../../utilities/error-common';\nimport { OpenAICompletionProvider } from './providers/openai-provider';\n\nexport enum LLMProvider {\n\tOPENAI = 'openai',\n\tGEMINI = 'gemini',\n}\n\ntype ProviderFactory = () => Promise<IAICompletionProvider>;\n\nexport class LLMCompletionService {\n\tprivate providerInstance: IAICompletionProvider | null = null;\n\n\tprivate readonly factories: Record<LLMProvider, ProviderFactory> = {\n\t\t[LLMProvider.OPENAI]: async () => {\n\t\t\tconst apiKey = await getLibraries().getSecretsService().getKey('OPENAI_API_KEY');\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow badRequestError(`No API key found for provider ${LLMProvider.OPENAI}`);\n\t\t\t}\n\t\t\treturn new OpenAICompletionProvider(apiKey, 'gpt-5-mini');\n\t\t},\n\t\t[LLMProvider.GEMINI]: async () => {\n\t\t\tthrow badRequestError(`Provider ${LLMProvider.GEMINI} is not implemented yet`);\n\t\t},\n\t};\n\n\tconstructor(private readonly provider: LLMProvider) {}\n\n\tasync generatePromptVariants(\n\t\tpayload: ItemTextInput[],\n\t\taiConfigurations: AiConfiguration\n\t): Promise<TextVariantResult[]> {\n\t\tconst provider = await this.getProvider();\n\t\tconsole.log(\n\t\t\t`You are using llm provider: ${this.provider} with model: ${aiConfigurations.model ?? 'gpt-5-mini'}`\n\t\t);\n\t\tconst options = {\n\t\t\tconcurrency: aiConfigurations.concurrency ?? 10,\n\t\t};\n\t\treturn provider.generateSearchVariants(payload, aiConfigurations.model, aiConfigurations.instructions, options);\n\t}\n\n\tprivate async getProvider(): Promise<IAICompletionProvider> {\n\t\tif (!this.providerInstance) {\n\t\t\tconst factory = this.factories[this.provider];\n\t\t\tif (!factory) {\n\t\t\t\tthrow badRequestError(`Unsupported transliteration provider: ${this.provider}`);\n\t\t\t}\n\t\t\tthis.providerInstance = await factory();\n\t\t}\n\t\treturn this.providerInstance;\n\t}\n}\n"]}
1
+ {"version":3,"file":"llm-provider-service.js","sourceRoot":"/","sources":["libraries/llm/llm-provider-service.ts"],"names":[],"mappings":";;;AAAA,6BAAqC;AAOrC,+DAA+D;AAC/D,iEAAuE;AAEvE,IAAY,WAGX;AAHD,WAAY,WAAW;IACtB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;AAClB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB;AAID,MAAa,oBAAoB;IAgB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AA6B,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;YACrE,CAAC;YACD,IAAI,CAAC,gBAAgB,GAAG,MAAM,OAAO,EAAE,CAAC;QACzC,CAAC;QACD,OAAO,IAAI,CAAC,gBAAgB,CAAC;IAC9B,CAAC;CACD;AA3CD,oDA2CC","sourcesContent":["import { getLibraries } from '../..';\nimport {\n\tItemTextInput,\n\tAiConfiguration,\n\tTextVariantResult,\n\tIAICompletionProvider,\n} from './interfaces/common-llm-interfaces';\nimport { badRequestError } from '../../utilities/error-common';\nimport { OpenAICompletionProvider } from './providers/openai-provider';\n\nexport enum LLMProvider {\n\tOPENAI = 'openai',\n\tGEMINI = 'gemini',\n}\n\ntype ProviderFactory = () => Promise<IAICompletionProvider>;\n\nexport class LLMCompletionService {\n\tprivate providerInstance: IAICompletionProvider | null = null;\n\n\tprivate readonly factories: Record<LLMProvider, ProviderFactory> = {\n\t\t[LLMProvider.OPENAI]: async () => {\n\t\t\tconst apiKey = await getLibraries().getSecretsService().getKey('OPENAI_API_KEY');\n\t\t\tif (!apiKey) {\n\t\t\t\tthrow badRequestError(`No API key found for provider ${LLMProvider.OPENAI}`);\n\t\t\t}\n\t\t\treturn new OpenAICompletionProvider(apiKey, 'gpt-5-mini');\n\t\t},\n\t\t[LLMProvider.GEMINI]: async () => {\n\t\t\tthrow badRequestError(`Provider ${LLMProvider.GEMINI} is not implemented yet`);\n\t\t},\n\t};\n\n\tconstructor(private readonly provider: LLMProvider) {}\n\n\tasync generateSearchVariants(\n\t\tpayload: ItemTextInput[],\n\t\taiConfigurations: AiConfiguration\n\t): Promise<TextVariantResult[]> {\n\t\tconst provider = await this.getProvider();\n\t\tconsole.log(\n\t\t\t`You are using llm provider: ${this.provider} with model: ${aiConfigurations.model ?? 'gpt-5-mini'}`\n\t\t);\n\t\treturn provider.generateSearchVariantsBatch(\n\t\t\tpayload,\n\t\t\taiConfigurations.model,\n\t\t\taiConfigurations.instructions\n\t\t);\n\t}\n\n\tprivate async getProvider(): Promise<IAICompletionProvider> {\n\t\tif (!this.providerInstance) {\n\t\t\tconst factory = this.factories[this.provider];\n\t\t\tif (!factory) {\n\t\t\t\tthrow badRequestError(`Unsupported LLM provider: ${this.provider}`);\n\t\t\t}\n\t\t\tthis.providerInstance = await factory();\n\t\t}\n\t\treturn this.providerInstance;\n\t}\n}"]}
@@ -3,18 +3,7 @@ export declare class OpenAICompletionProvider implements IAICompletionProvider {
3
3
  private readonly client;
4
4
  private readonly model;
5
5
  constructor(apiKey: string | undefined, model?: string);
6
- generateSearchVariants(items: ItemTextInput[], model?: string, instructions?: string, options?: {
7
- batchThreshold?: number;
8
- concurrency?: number;
9
- maxRetries?: number;
10
- pollIntervalMs?: number;
11
- maxWaitMs?: number;
12
- }): Promise<TextVariantResult[]>;
13
- generatePromptVariantsRealtime(items: ItemTextInput[], model?: string, instructions?: string, options?: {
14
- concurrency?: number;
15
- maxRetries?: number;
16
- }): Promise<TextVariantResult[]>;
17
- generatePromptVariantsBatch(items: ItemTextInput[], model?: string, instructions?: string, options?: {
6
+ generateSearchVariantsBatch(items: ItemTextInput[], model?: string, instructions?: string, options?: {
18
7
  pollIntervalMs?: number;
19
8
  maxWaitMs?: number;
20
9
  }): Promise<TextVariantResult[]>;
@@ -45,111 +45,7 @@ class OpenAICompletionProvider {
45
45
  this.client = new openai_1.default({ apiKey });
46
46
  this.model = model;
47
47
  }
48
- async generateSearchVariants(items, model, instructions, options) {
49
- const batchThreshold = options?.batchThreshold ?? 1000;
50
- const mode = items.length >= batchThreshold ? 'batch' : 'realtime';
51
- console.log('generatePromptVariants: dispatching', {
52
- itemCount: items.length,
53
- batchThreshold,
54
- mode,
55
- });
56
- if (mode === 'batch') {
57
- console.log('Started batch processing generatePromptVariantsBatch');
58
- return this.generatePromptVariantsBatch(items, model, instructions, {
59
- pollIntervalMs: options?.pollIntervalMs,
60
- maxWaitMs: options?.maxWaitMs,
61
- });
62
- }
63
- console.log('Started realtime processing generatePromptVariantsRealtime');
64
- return this.generatePromptVariantsRealtime(items, model, instructions, {
65
- concurrency: options?.concurrency,
66
- maxRetries: options?.maxRetries,
67
- });
68
- }
69
- async generatePromptVariantsRealtime(items, model, instructions, options) {
70
- const concurrency = options?.concurrency ?? 10;
71
- const maxRetries = options?.maxRetries ?? 3;
72
- try {
73
- if (items.length === 0)
74
- return [];
75
- const { fields, instructions: defaultInstructions } = this.buildVariantRequest();
76
- const finalInstructions = instructions ?? defaultInstructions;
77
- const finalModel = model ?? this.model;
78
- const schema = this.buildJsonSchema(fields);
79
- console.log('generatePromptVariantsRealtime: starting', {
80
- itemCount: items.length,
81
- finalModel,
82
- concurrency,
83
- });
84
- const runOne = async ({ itemId, text }, attempt = 1) => {
85
- try {
86
- const response = await this.client.responses.create({
87
- model: finalModel,
88
- instructions: finalInstructions,
89
- input: text,
90
- text: {
91
- format: {
92
- type: 'json_schema',
93
- name: 'text_variants',
94
- schema,
95
- strict: true,
96
- },
97
- },
98
- });
99
- const outputText = response.output_text ??
100
- response.output
101
- ?.find((o) => o.type === 'message')
102
- ?.content?.find((c) => c.type === 'output_text')?.text;
103
- if (!outputText) {
104
- throw new Error('empty output_text in response');
105
- }
106
- let parsed;
107
- try {
108
- parsed = JSON.parse(outputText);
109
- }
110
- catch {
111
- console.error(`generatePromptVariantsRealtime: failed to parse output for itemId=${itemId}`, outputText);
112
- return { itemId, original: text };
113
- }
114
- return { itemId, original: text, ...parsed };
115
- }
116
- catch (error) {
117
- const status = error?.status ?? error?.response?.status;
118
- const isRetryable = status === 429 || status === 500 || status === 503;
119
- if (isRetryable && attempt <= maxRetries) {
120
- const backoffMs = 1000 * 2 ** attempt;
121
- console.warn(`generatePromptVariantsRealtime: retryable error (status=${status}) for itemId=${itemId}, attempt ${attempt}/${maxRetries}, retrying in ${backoffMs}ms`);
122
- await new Promise(resolve => setTimeout(resolve, backoffMs));
123
- return runOne({ itemId, text }, attempt + 1);
124
- }
125
- console.error(`generatePromptVariantsRealtime: failed for itemId=${itemId} after ${attempt} attempt(s)`, error);
126
- return { itemId, original: text };
127
- }
128
- };
129
- const results = [];
130
- for (let i = 0; i < items.length; i += concurrency) {
131
- const chunk = items.slice(i, i + concurrency);
132
- const chunkResults = await Promise.all(chunk.map(item => runOne(item)));
133
- results.push(...chunkResults);
134
- console.log(`generatePromptVariantsRealtime: progress ${Math.min(i + concurrency, items.length)}/${items.length}`);
135
- }
136
- const failedCount = results.filter(r => Object.keys(r).length <= 2).length;
137
- console.log('generatePromptVariantsRealtime: done', {
138
- total: items.length,
139
- failed: failedCount,
140
- });
141
- return results;
142
- }
143
- catch (error) {
144
- console.error('generatePromptVariantsRealtime failed', {
145
- error,
146
- itemCount: items.length,
147
- model,
148
- });
149
- throw error;
150
- }
151
- }
152
- async generatePromptVariantsBatch(items, model, instructions, options) {
48
+ async generateSearchVariantsBatch(items, model, instructions, options) {
153
49
  try {
154
50
  const { fields, instructions: defaultInstructions } = this.buildVariantRequest();
155
51
  const finalInstructions = instructions ?? defaultInstructions;
@@ -179,10 +75,18 @@ class OpenAICompletionProvider {
179
75
  },
180
76
  }))
181
77
  .join('\n');
78
+ console.log({ jsonl });
182
79
  const inputFile = await this.client.files.create({
183
80
  file: await (0, openai_1.toFile)(Buffer.from(jsonl, 'utf-8'), 'batch-input.jsonl'),
184
81
  purpose: 'batch',
185
82
  });
83
+ console.log({ inputFile });
84
+ const openAiBatchApiPayload = {
85
+ input_file_id: inputFile.id,
86
+ endpoint: '/v1/responses',
87
+ completion_window: '24h',
88
+ };
89
+ console.log({ openAiBatchApiPayload });
186
90
  let batch = await this.client.batches.create({
187
91
  input_file_id: inputFile.id,
188
92
  endpoint: '/v1/responses',
@@ -1 +1 @@
1
- {"version":3,"file":"openai-provider.js","sourceRoot":"/","sources":["libraries/llm/providers/openai-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAwC;AAGxC,MAAa,wBAAwB;IACnB,MAAM,CAAS;IACf,KAAK,CAAS;IAE/B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e,CAAC;QACtC,IAAI,CAAC,MAAM;YAAE,OAAO,MAAM,CAAC;QAE3B,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7D,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,CAAC;QAEvC,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;YACrD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAChC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QACtC,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAEO,eAAe,CAAC,MAAmC;QAC1D,MAAM,UAAU,GAAwB,EAAE,CAAC;QAC3C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC5B,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC;QAClE,CAAC;QAED,OAAO;YACN,IAAI,EAAE,QAAQ;YACd,UAAU;YACV,QAAQ,EAAE,MAAM;YAChB,oBAAoB,EAAE,KAAK;SAC3B,CAAC;IACH,CAAC;CACD;AArWD,4DAqWC","sourcesContent":["import OpenAI, { toFile } from 'openai';\nimport { IAICompletionProvider, ItemTextInput, TextVariantResult } from '../interfaces/common-llm-interfaces';\n\nexport class OpenAICompletionProvider implements IAICompletionProvider {\n\tprivate readonly client: OpenAI;\n\tprivate readonly model: string;\n\n\tconstructor(apiKey: string | undefined, model: string = 'gpt-5-mini') {\n\t\tif (!apiKey) {\n\t\t\tthrow new Error('OPENAI_API_KEY is required to construct OpenAICompletionProvider');\n\t\t}\n\t\tthis.client = new OpenAI({ apiKey });\n\t\tthis.model = model;\n\t}\n\n\t// ── Public dispatcher ───────────────────────────────────────────\n\t// Use this as the default entry point. It picks realtime (fast,\n\t// synchronous fan-out) vs batch (cheap, unbounded latency) based\n\t// on item count so callers don't have to decide manually.\n\n\tasync generateSearchVariants(\n\t\titems: ItemTextInput[],\n\t\tmodel?: string,\n\t\tinstructions?: string,\n\t\toptions?: {\n\t\t\tbatchThreshold?: number; // item count at/above which we switch to Batch API\n\t\t\tconcurrency?: number; // realtime fan-out concurrency\n\t\t\tmaxRetries?: number; // realtime retry count on 429/500/503\n\t\t\tpollIntervalMs?: number; // batch poll interval\n\t\t\tmaxWaitMs?: number; // batch max wait\n\t\t}\n\t): Promise<TextVariantResult[]> {\n\t\tconst batchThreshold = options?.batchThreshold ?? 1000;\n\t\tconst mode = items.length >= batchThreshold ? 'batch' : 'realtime';\n\n\t\tconsole.log('generatePromptVariants: dispatching', {\n\t\t\titemCount: items.length,\n\t\t\tbatchThreshold,\n\t\t\tmode,\n\t\t});\n\n\t\tif (mode === 'batch') {\n\t\t\tconsole.log('Started batch processing generatePromptVariantsBatch');\n\t\t\treturn this.generatePromptVariantsBatch(items, model, instructions, {\n\t\t\t\tpollIntervalMs: options?.pollIntervalMs,\n\t\t\t\tmaxWaitMs: options?.maxWaitMs,\n\t\t\t});\n\t\t}\n\n\t\tconsole.log('Started realtime processing generatePromptVariantsRealtime');\n\t\treturn this.generatePromptVariantsRealtime(items, model, instructions, {\n\t\t\tconcurrency: options?.concurrency,\n\t\t\tmaxRetries: options?.maxRetries,\n\t\t});\n\t}\n\n\t// ── Realtime path (fast) ────────────────────────────────────────\n\t// Direct synchronous calls, fanned out with bounded concurrency.\n\t// Use this whenever you need the result back in the same request/\n\t// job — seconds to low minutes for hundreds of items, not hours.\n\n\tasync generatePromptVariantsRealtime(\n\t\titems: ItemTextInput[],\n\t\tmodel?: string,\n\t\tinstructions?: string,\n\t\toptions?: { concurrency?: number; maxRetries?: number }\n\t): Promise<TextVariantResult[]> {\n\t\tconst concurrency = options?.concurrency ?? 10;\n\t\tconst maxRetries = options?.maxRetries ?? 3;\n\n\t\ttry {\n\t\t\tif (items.length === 0) return [];\n\n\t\t\tconst { fields, instructions: defaultInstructions } = this.buildVariantRequest();\n\t\t\tconst finalInstructions = instructions ?? defaultInstructions;\n\t\t\tconst finalModel = model ?? this.model;\n\t\t\tconst schema = this.buildJsonSchema(fields);\n\n\t\t\tconsole.log('generatePromptVariantsRealtime: starting', {\n\t\t\t\titemCount: items.length,\n\t\t\t\tfinalModel,\n\t\t\t\tconcurrency,\n\t\t\t});\n\n\t\t\tconst runOne = async ({ itemId, text }: ItemTextInput, attempt = 1): Promise<TextVariantResult> => {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await this.client.responses.create({\n\t\t\t\t\t\tmodel: finalModel,\n\t\t\t\t\t\tinstructions: finalInstructions,\n\t\t\t\t\t\tinput: text,\n\t\t\t\t\t\ttext: {\n\t\t\t\t\t\t\tformat: {\n\t\t\t\t\t\t\t\ttype: 'json_schema',\n\t\t\t\t\t\t\t\tname: 'text_variants',\n\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\tstrict: true,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t});\n\n\t\t\t\t\tconst outputText =\n\t\t\t\t\t\t(response as any).output_text ??\n\t\t\t\t\t\t(response as any).output\n\t\t\t\t\t\t\t?.find((o: any) => o.type === 'message')\n\t\t\t\t\t\t\t?.content?.find((c: any) => c.type === 'output_text')?.text;\n\n\t\t\t\t\tif (!outputText) {\n\t\t\t\t\t\tthrow new Error('empty output_text in response');\n\t\t\t\t\t}\n\n\t\t\t\t\tlet parsed: Record<string, unknown>;\n\t\t\t\t\ttry {\n\t\t\t\t\t\tparsed = JSON.parse(outputText);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`generatePromptVariantsRealtime: failed to parse output for itemId=${itemId}`,\n\t\t\t\t\t\t\toutputText\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn { itemId, original: text };\n\t\t\t\t\t}\n\n\t\t\t\t\treturn { itemId, original: text, ...parsed };\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\tconst status = error?.status ?? error?.response?.status;\n\t\t\t\t\tconst isRetryable = status === 429 || status === 500 || status === 503;\n\n\t\t\t\t\tif (isRetryable && attempt <= maxRetries) {\n\t\t\t\t\t\tconst backoffMs = 1000 * 2 ** attempt; // 2s, 4s, 8s...\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`generatePromptVariantsRealtime: retryable error (status=${status}) for itemId=${itemId}, attempt ${attempt}/${maxRetries}, retrying in ${backoffMs}ms`\n\t\t\t\t\t\t);\n\t\t\t\t\t\tawait new Promise(resolve => setTimeout(resolve, backoffMs));\n\t\t\t\t\t\treturn runOne({ itemId, text }, attempt + 1);\n\t\t\t\t\t}\n\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`generatePromptVariantsRealtime: failed for itemId=${itemId} after ${attempt} attempt(s)`,\n\t\t\t\t\t\terror\n\t\t\t\t\t);\n\t\t\t\t\treturn { itemId, original: text };\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst results: TextVariantResult[] = [];\n\t\t\tfor (let i = 0; i < items.length; i += concurrency) {\n\t\t\t\tconst chunk = items.slice(i, i + concurrency);\n\t\t\t\tconst chunkResults = await Promise.all(chunk.map(item => runOne(item)));\n\t\t\t\tresults.push(...chunkResults);\n\t\t\t\tconsole.log(\n\t\t\t\t\t`generatePromptVariantsRealtime: progress ${Math.min(i + concurrency, items.length)}/${items.length}`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst failedCount = results.filter(r => Object.keys(r).length <= 2).length;\n\t\t\tconsole.log('generatePromptVariantsRealtime: done', {\n\t\t\t\ttotal: items.length,\n\t\t\t\tfailed: failedCount,\n\t\t\t});\n\n\t\t\treturn results;\n\t\t} catch (error) {\n\t\t\tconsole.error('generatePromptVariantsRealtime failed', {\n\t\t\t\terror,\n\t\t\t\titemCount: items.length,\n\t\t\t\tmodel,\n\t\t\t});\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// ── Batch path (cheap, slow, unbounded latency) ─────────────────\n\t// Only use directly for large (1000+), non-urgent jobs kicked off\n\t// from a background worker/cron — not from a request/response path.\n\tasync generatePromptVariantsBatch(\n\t\titems: ItemTextInput[],\n\t\tmodel?: string,\n\t\tinstructions?: string,\n\t\toptions?: { pollIntervalMs?: number; maxWaitMs?: number }\n\t): Promise<TextVariantResult[]> {\n\t\ttry {\n\t\t\tconst { fields, instructions: defaultInstructions } = this.buildVariantRequest();\n\t\t\tconst finalInstructions = instructions ?? defaultInstructions;\n\t\t\tconst finalModel = model ?? this.model;\n\t\t\t\n\t\t\tconsole.log(`You are using llm provider model: ${finalModel}`);\n\n\t\t\tconst schema = this.buildJsonSchema(fields);\n\n\t\t\tif (items.length > 50_000) {\n\t\t\t\tthrow new Error('Batch API supports max 50,000 requests per batch — chunk your items first.');\n\t\t\t}\n\n\t\t\t// 1. Build JSONL\n\t\t\tconst jsonl = items\n\t\t\t\t.map(({ itemId, text }) =>\n\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\tcustom_id: itemId,\n\t\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\t\turl: '/v1/responses',\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tmodel: finalModel,\n\t\t\t\t\t\t\tinstructions: finalInstructions,\n\t\t\t\t\t\t\tinput: text,\n\t\t\t\t\t\t\ttext: {\n\t\t\t\t\t\t\t\tformat: {\n\t\t\t\t\t\t\t\t\ttype: 'json_schema',\n\t\t\t\t\t\t\t\t\tname: 'text_variants',\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tstrict: true,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t\t.join('\\n');\n\n\t\t\t// 2. Upload input file\n\t\t\tconst inputFile = await this.client.files.create({\n\t\t\t\tfile: await toFile(Buffer.from(jsonl, 'utf-8'), 'batch-input.jsonl'),\n\t\t\t\tpurpose: 'batch',\n\t\t\t});\n\n\t\t\t// 3. Create batch job\n\t\t\tlet batch = await this.client.batches.create({\n\t\t\t\tinput_file_id: inputFile.id,\n\t\t\t\tendpoint: '/v1/responses',\n\t\t\t\tcompletion_window: '24h',\n\t\t\t});\t\t\t\n\n\t\t\t// 4. Poll until done\n\t\t\tbatch = await this.pollBatch(batch.id, options?.pollIntervalMs, options?.maxWaitMs);\n\n\t\t\tif (batch.status !== 'completed') {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Batch ${batch.id} ended with status \"${batch.status}\" (${batch.request_counts?.failed ?? 0} failed)`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// 5. Parse output\n\t\t\tconst outputById = await this.readJsonlFile(batch.output_file_id);\n\t\t\tconst errorsById = await this.readJsonlFile(batch.error_file_id);\t\t\t\n\n\t\t\t// 6. Merge results\n\t\t\treturn items.map(({ itemId, text }) => {\n\t\t\t\tconst record = outputById.get(itemId);\n\t\t\t\tconst body = record?.response?.body;\n\n\t\t\t\tconst outputText =\n\t\t\t\t\tbody?.output_text ??\n\t\t\t\t\tbody?.output\n\t\t\t\t\t\t?.find((o: any) => o.type === 'message')\n\t\t\t\t\t\t?.content?.find((c: any) => c.type === 'output_text')?.text;\n\n\t\t\t\tif (!outputText) {\n\t\t\t\t\tconst err = errorsById.get(itemId);\n\t\t\t\t\tconsole.error(`generatePromptVariantsBatch: no output for itemId=${itemId}`, err ?? record?.error);\n\t\t\t\t\treturn { itemId, original: text };\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\treturn { itemId, original: text, ...JSON.parse(outputText) };\n\t\t\t\t} catch {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`generatePromptVariantsBatch: failed to parse output for itemId=${itemId}`,\n\t\t\t\t\t\toutputText\n\t\t\t\t\t);\n\t\t\t\t\treturn { itemId, original: text };\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconsole.error('generatePromptVariantsBatch failed', {\n\t\t\t\terror,\n\t\t\t\titemCount: items.length,\n\t\t\t\tmodel,\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// ── Helpers ──────────────────────────────────────────────────────\n\n\tprivate buildVariantRequest(): {\n\t\tfields: (keyof TextVariantResult)[];\n\t\tinstructions: string;\n\t} {\n\t\ttype GeneratedField = Exclude<keyof TextVariantResult, 'original' | 'itemId'>;\n\n\t\tconst fieldDescriptions: Record<GeneratedField, string> = {\n\t\t\tarabic:\n\t\t\t\t'The Arabic translation of the word/phrase, written in Arabic script (e.g. \"زيتون\" for \"olive\"). Provide 1-3 common variants if applicable.',\n\t\t\tarabizi:\n\t\t\t\t'The Arabic word\\'s meaning, written phonetically in Latin script/numerals — i.e. Arabizi (e.g. \"zaytoon\"). Provide 1-3 common spelling variants.',\n\t\t\tarabicTransliteration:\n\t\t\t\t'The original word spelled phonetically in Arabic script, NOT translated (e.g. \"أوليف\" for \"olive\"). Useful when there is no native Arabic equivalent.',\n\t\t};\n\n\t\tconst fields = Object.keys(fieldDescriptions) as GeneratedField[];\n\n\t\tconst instructions = [\n\t\t\t'You generate search-name variants for a food delivery app product/shop name.',\n\t\t\t'For the given input text, return ONLY the following fields as arrays of strings:',\n\t\t\t...fields.map(f => `- ${f}: ${fieldDescriptions[f]}`),\n\t\t\t'Return strict JSON matching the schema. No extra commentary, no extra fields.',\n\t\t].join('\\n');\n\n\t\treturn { fields, instructions };\n\t}\n\n\tprivate async pollBatch(\n\t\tbatchId: string,\n\t\tintervalMs = 5000,\n\t\tmaxWaitMs = 24 * 60 * 60 * 1000\n\t): Promise<OpenAI.Batches.Batch> {\n\t\tconst terminal = new Set(['completed', 'failed', 'expired', 'cancelled']);\n\t\tconst start = Date.now();\n\n\t\twhile (true) {\n\t\t\tconst batch = await this.client.batches.retrieve(batchId);\n\t\t\tconsole.log(\n\t\t\t\t`pollBatch: ${batchId} status=${batch.status} elapsed=${Math.round((Date.now() - start) / 1000)}s`\n\t\t\t);\n\t\t\tif (terminal.has(batch.status)) return batch;\n\n\t\t\tif (Date.now() - start > maxWaitMs) {\n\t\t\t\tthrow new Error(`Batch ${batchId} did not finish within ${maxWaitMs}ms (status: ${batch.status})`);\n\t\t\t}\n\n\t\t\tawait new Promise(resolve => setTimeout(resolve, intervalMs));\n\t\t}\n\t}\n\n\tprivate async readJsonlFile(fileId: string | null | undefined): Promise<Map<string, any>> {\n\t\tconst result = new Map<string, any>();\n\t\tif (!fileId) return result;\n\n\t\tconst fileResponse = await this.client.files.content(fileId);\n\t\tconst text = await fileResponse.text();\n\n\t\tfor (const line of text.split('\\n').filter(Boolean)) {\n\t\t\tconst record = JSON.parse(line);\n\t\t\tresult.set(record.custom_id, record);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tprivate buildJsonSchema(fields: (keyof TextVariantResult)[]) {\n\t\tconst properties: Record<string, any> = {};\n\t\tfor (const field of fields) {\n\t\t\tproperties[field] = { type: 'array', items: { type: 'string' } };\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'object',\n\t\t\tproperties,\n\t\t\trequired: fields,\n\t\t\tadditionalProperties: false,\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"openai-provider.js","sourceRoot":"/","sources":["libraries/llm/providers/openai-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAwC;AAGxC,MAAa,wBAAwB;IACnB,MAAM,CAAS;IACf,KAAK,CAAS;IAE/B,YAAY,MAA0B,EAAE,QAAgB,YAAY;QACnE,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;QACrF,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;QACrC,IA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\nimport { IAICompletionProvider, ItemTextInput, TextVariantResult } from '../interfaces/common-llm-interfaces';\n\nexport class OpenAICompletionProvider implements IAICompletionProvider {\n\tprivate readonly client: OpenAI;\n\tprivate readonly model: string;\n\n\tconstructor(apiKey: string | undefined, model: string = 'gpt-5-mini') {\n\t\tif (!apiKey) {\n\t\t\tthrow new Error('OPENAI_API_KEY is required to construct OpenAICompletionProvider');\n\t\t}\n\t\tthis.client = new OpenAI({ apiKey });\n\t\tthis.model = model;\n\t}\n\n\t// ── Batch path (cheap, slow, unbounded latency) ─────────────────\n\t// Use for large, non-urgent jobs kicked off from a background\n\t// worker/cron — not from a request/response path.\n\tasync generateSearchVariantsBatch(\n\t\titems: ItemTextInput[],\n\t\tmodel?: string,\n\t\tinstructions?: string,\n\t\toptions?: { pollIntervalMs?: number; maxWaitMs?: number }\n\t): Promise<TextVariantResult[]> {\n\t\ttry {\n\t\t\tconst { fields, instructions: defaultInstructions } = this.buildVariantRequest();\n\t\t\tconst finalInstructions = instructions ?? defaultInstructions;\n\t\t\tconst finalModel = model ?? this.model;\n\n\t\t\tconsole.log(`You are using llm provider model: ${finalModel}`);\n\n\t\t\tconst schema = this.buildJsonSchema(fields);\n\n\t\t\tif (items.length > 50_000) {\n\t\t\t\tthrow new Error('Batch API supports max 50,000 requests per batch — chunk your items first.');\n\t\t\t}\n\n\t\t\t// 1. Build JSONL\n\t\t\tconst jsonl = items\n\t\t\t\t.map(({ itemId, text }) =>\n\t\t\t\t\tJSON.stringify({\n\t\t\t\t\t\tcustom_id: itemId,\n\t\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\t\turl: '/v1/responses',\n\t\t\t\t\t\tbody: {\n\t\t\t\t\t\t\tmodel: finalModel,\n\t\t\t\t\t\t\tinstructions: finalInstructions,\n\t\t\t\t\t\t\tinput: text,\n\t\t\t\t\t\t\ttext: {\n\t\t\t\t\t\t\t\tformat: {\n\t\t\t\t\t\t\t\t\ttype: 'json_schema',\n\t\t\t\t\t\t\t\t\tname: 'text_variants',\n\t\t\t\t\t\t\t\t\tschema,\n\t\t\t\t\t\t\t\t\tstrict: true,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t\t.join('\\n');\n\t\t\tconsole.log({ jsonl})\n\t\t\t// 2. Upload input file\n\t\t\tconst inputFile = await this.client.files.create({\n\t\t\t\tfile: await toFile(Buffer.from(jsonl, 'utf-8'), 'batch-input.jsonl'),\n\t\t\t\tpurpose: 'batch',\n\t\t\t});\n\t\t\tconsole.log({ inputFile})\n\t\t\t// 3. Create batch job\n\t\t\tconst openAiBatchApiPayload = {\n\t\t\t\tinput_file_id: inputFile.id,\n\t\t\t\tendpoint: '/v1/responses',\n\t\t\t\tcompletion_window: '24h',\n\t\t\t}\n\t\t\tconsole.log({ openAiBatchApiPayload })\n\t\t\tlet batch = await this.client.batches.create({\n\t\t\t\tinput_file_id: inputFile.id,\n\t\t\t\tendpoint: '/v1/responses',\n\t\t\t\tcompletion_window: '24h',\n\t\t\t});\n\n\t\t\t// 4. Poll until done\n\t\t\tbatch = await this.pollBatch(batch.id, options?.pollIntervalMs, options?.maxWaitMs);\n\n\t\t\tif (batch.status !== 'completed') {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Batch ${batch.id} ended with status \"${batch.status}\" (${batch.request_counts?.failed ?? 0} failed)`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// 5. Parse output\n\t\t\tconst outputById = await this.readJsonlFile(batch.output_file_id);\n\t\t\tconst errorsById = await this.readJsonlFile(batch.error_file_id);\n\n\t\t\t// 6. Merge results\n\t\t\treturn items.map(({ itemId, text }) => {\n\t\t\t\tconst record = outputById.get(itemId);\n\t\t\t\tconst body = record?.response?.body;\n\n\t\t\t\tconst outputText =\n\t\t\t\t\tbody?.output_text ??\n\t\t\t\t\tbody?.output\n\t\t\t\t\t\t?.find((o: any) => o.type === 'message')\n\t\t\t\t\t\t?.content?.find((c: any) => c.type === 'output_text')?.text;\n\n\t\t\t\tif (!outputText) {\n\t\t\t\t\tconst err = errorsById.get(itemId);\n\t\t\t\t\tconsole.error(`generatePromptVariantsBatch: no output for itemId=${itemId}`, err ?? record?.error);\n\t\t\t\t\treturn { itemId, original: text };\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\treturn { itemId, original: text, ...JSON.parse(outputText) };\n\t\t\t\t} catch {\n\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t`generatePromptVariantsBatch: failed to parse output for itemId=${itemId}`,\n\t\t\t\t\t\toutputText\n\t\t\t\t\t);\n\t\t\t\t\treturn { itemId, original: text };\n\t\t\t\t}\n\t\t\t});\n\t\t} catch (error) {\n\t\t\tconsole.error('generatePromptVariantsBatch failed', {\n\t\t\t\terror,\n\t\t\t\titemCount: items.length,\n\t\t\t\tmodel,\n\t\t\t});\n\n\t\t\tthrow error;\n\t\t}\n\t}\n\n\t// ── Helpers ──────────────────────────────────────────────────────\n\tprivate buildVariantRequest(): {\n\t\tfields: (keyof TextVariantResult)[];\n\t\tinstructions: string;\n\t} {\n\t\ttype GeneratedField = Exclude<keyof TextVariantResult, 'original' | 'itemId'>;\n\n\t\tconst fieldDescriptions: Record<GeneratedField, string> = {\n\t\t\tarabic:\n\t\t\t\t'The Arabic translation of the word/phrase, written in Arabic script (e.g. \"زيتون\" for \"olive\"). Provide 1-3 common variants if applicable.',\n\t\t\tarabizi:\n\t\t\t\t'The Arabic word\\'s meaning, written phonetically in Latin script/numerals — i.e. Arabizi (e.g. \"zaytoon\"). Provide 1-3 common spelling variants.',\n\t\t\tarabicTransliteration:\n\t\t\t\t'The original word spelled phonetically in Arabic script, NOT translated (e.g. \"أوليف\" for \"olive\"). Useful when there is no native Arabic equivalent.',\n\t\t};\n\n\t\tconst fields = Object.keys(fieldDescriptions) as GeneratedField[];\n\n\t\tconst instructions = [\n\t\t\t'You generate search-name variants for a food delivery app product/shop name.',\n\t\t\t'For the given input text, return ONLY the following fields as arrays of strings:',\n\t\t\t...fields.map(f => `- ${f}: ${fieldDescriptions[f]}`),\n\t\t\t'Return strict JSON matching the schema. No extra commentary, no extra fields.',\n\t\t].join('\\n');\n\n\t\treturn { fields, instructions };\n\t}\n\n\tprivate async pollBatch(\n\t\tbatchId: string,\n\t\tintervalMs = 5000,\n\t\tmaxWaitMs = 24 * 60 * 60 * 1000\n\t): Promise<OpenAI.Batches.Batch> {\n\t\tconst terminal = new Set(['completed', 'failed', 'expired', 'cancelled']);\n\t\tconst start = Date.now();\n\n\t\twhile (true) {\n\t\t\tconst batch = await this.client.batches.retrieve(batchId);\n\t\t\tconsole.log(\n\t\t\t\t`pollBatch: ${batchId} status=${batch.status} elapsed=${Math.round((Date.now() - start) / 1000)}s`\n\t\t\t);\n\t\t\tif (terminal.has(batch.status)) return batch;\n\n\t\t\tif (Date.now() - start > maxWaitMs) {\n\t\t\t\tthrow new Error(`Batch ${batchId} did not finish within ${maxWaitMs}ms (status: ${batch.status})`);\n\t\t\t}\n\n\t\t\tawait new Promise(resolve => setTimeout(resolve, intervalMs));\n\t\t}\n\t}\n\n\tprivate async readJsonlFile(fileId: string | null | undefined): Promise<Map<string, any>> {\n\t\tconst result = new Map<string, any>();\n\t\tif (!fileId) return result;\n\n\t\tconst fileResponse = await this.client.files.content(fileId);\n\t\tconst text = await fileResponse.text();\n\n\t\tfor (const line of text.split('\\n').filter(Boolean)) {\n\t\t\tconst record = JSON.parse(line);\n\t\t\tresult.set(record.custom_id, record);\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tprivate buildJsonSchema(fields: (keyof TextVariantResult)[]) {\n\t\tconst properties: Record<string, any> = {};\n\t\tfor (const field of fields) {\n\t\t\tproperties[field] = { type: 'array', items: { type: 'string' } };\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'object',\n\t\t\tproperties,\n\t\t\trequired: fields,\n\t\t\tadditionalProperties: false,\n\t\t};\n\t}\n}\n"]}
@@ -47,5 +47,4 @@ export declare class Setting extends TimeStamps {
47
47
  enableFlags: Map<string, any>;
48
48
  companyInfo?: CompanyInfo;
49
49
  showAreebaDefaultOtpPage?: boolean;
50
- isProximityCheckEnabled?: boolean;
51
50
  }
@@ -60,7 +60,6 @@ let Setting = class Setting extends defaultClasses_1.TimeStamps {
60
60
  enableFlags;
61
61
  companyInfo;
62
62
  showAreebaDefaultOtpPage;
63
- isProximityCheckEnabled;
64
63
  };
65
64
  exports.Setting = Setting;
66
65
  __decorate([
@@ -191,10 +190,6 @@ __decorate([
191
190
  (0, typegoose_1.prop)({ type: Boolean, default: false }),
192
191
  __metadata("design:type", Boolean)
193
192
  ], Setting.prototype, "showAreebaDefaultOtpPage", void 0);
194
- __decorate([
195
- (0, typegoose_1.prop)({ type: Boolean, default: true }),
196
- __metadata("design:type", Boolean)
197
- ], Setting.prototype, "isProximityCheckEnabled", void 0);
198
193
  exports.Setting = Setting = __decorate([
199
194
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'settings' } })
200
195
  ], Setting);
@@ -1 +1 @@
1
- {"version":3,"file":"setting.model.js","sourceRoot":"/","sources":["libraries/mongo/models/setting.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA0D;AAC1D,8DAA2D;AAC3D,sEAA4D;AAC5D,kEAA6D;AAC7D,wEAA8D;AAC9D,wEAA8D;AAC9D,0EAAgE;AAChE,4EAAkE;AAClE,8EAAoE;AACpE,4EAAqE;AACrE,wEAAsE;AACtE,oFAAyE;AACzE,4FAA0E;AAC1E,kDAA0E;AAC1E,8FAA4E;AAC5E,kGAAuF;AACvF,sGAA2F;AAC3F,8FAA2F;AAGpF,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,2BAAU;IAE/B,eAAe,CAAmB;IAGlC,iBAAiB,CAAqB;IAGtC,aAAa,CAAiB;IAG9B,eAAe,CAAmB;IAGlC,cAAc,CAAkB;IAGhC,YAAY,CAAgB;IAG5B,0BAA0B,CAA8B;IAGxD,eAAe,CAAU;IAGzB,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AW;4CAAC;AAG1B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;yDACE;AAGnC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;wDACE;kBAnG7B,OAAO;IADnB,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC;GAC/C,OAAO,CAoGnB","sourcesContent":["import { modelOptions, prop } from '@typegoose/typegoose';\nimport { WorkHourSetting } from './shared/work-hour.model';\nimport { CompanyInfo } from './embedded/company-info.model';\nimport { AppForceUpdate } from './embedded/app-force-update';\nimport { PlusSettings } from './embedded/plus-settings.model';\nimport { RiderSetting } from './embedded/rider-setting.model';\nimport { PayoutSetting } from './embedded/payout-setting.model';\nimport { CourierSetting } from './embedded/courier-setting.model';\nimport { CurrencySetting } from './embedded/currency-setting.model';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { RiderBatchesSettings } from './embedded/rider-batches.model';\nimport { ServiceFeeSetting } from './embedded/service-fee-setting.model';\nimport { DeliveryCharge } from './embedded/delivery-charge-setting.model';\nimport { LyxaTimeZoneEnum, PaymentMethod } from '../../../utilities/enum';\nimport { CustomerSupport } from './embedded/customer-support-numbers.model';\nimport { AgentNotificationSetting } from './embedded/agent-notification-setting.model';\nimport { BusinessDevelopmentSetting } from './embedded/business-development-setting.model';\nimport { CustomerSupportBatchesSettings } from './embedded/customer-support-batches.model';\n\n@modelOptions({ schemaOptions: { collection: 'settings' } })\nexport class Setting extends TimeStamps {\n\t@prop({ type: () => [DeliveryCharge] })\n\tpublic deliveryCharges: DeliveryCharge[];\n\n\t@prop({ type: ServiceFeeSetting })\n\tpublic serviceFeeSetting?: ServiceFeeSetting;\n\n\t@prop({ type: PayoutSetting })\n\tpublic payoutSetting?: PayoutSetting;\n\n\t@prop({ type: WorkHourSetting })\n\tpublic workHourSetting?: WorkHourSetting;\n\n\t@prop({ type: CourierSetting })\n\tpublic courierSetting?: CourierSetting;\n\n\t@prop({ type: RiderSetting })\n\tpublic riderSetting?: RiderSetting;\n\n\t@prop({ type: BusinessDevelopmentSetting })\n\tpublic businessDevelopmentSetting?: BusinessDevelopmentSetting;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic payLimitForUser?: number;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic concurrentOrderLimitForUser?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic vatPercentage?: number;\n\n\t@prop({ type: () => [Number], default: [] })\n\tpublic riderSearchRanges?: number[];\n\n\t@prop({ type: () => [RiderBatchesSettings], default: [] })\n\tpublic riderBatches?: RiderBatchesSettings[];\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistance?: number;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistanceInHomeScreen?: number;\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic units?: string[];\n\n\t@prop({ type: CurrencySetting })\n\tpublic currencySetting?: CurrencySetting;\n\n\t@prop({ type: () => [String], enum: PaymentMethod, default: [] })\n\tpublic paymentMethods?: PaymentMethod[];\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isGroupOrderEnabled?: boolean;\n\n\t@prop({ type: CustomerSupport })\n\tpublic customerSupport?: CustomerSupport;\n\n\t@prop({ type: () => [CustomerSupportBatchesSettings], default: [] })\n\tpublic customerSupportBatches?: CustomerSupportBatchesSettings[];\n\n\t@prop({ type: () => [PlusSettings], default: [] })\n\tpublic plusSettings?: PlusSettings[];\n\n\t@prop({ type: AgentNotificationSetting })\n\tpublic agentNotificationSetting?: AgentNotificationSetting;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic cashbackAmount?: number;\n\n\t@prop({ type: String, enum: LyxaTimeZoneEnum })\n\tpublic timezone?: LyxaTimeZoneEnum;\n\n\t@prop({ type: Number, min: 0, default: 600 })\n\tpublic bufferTimeInSeconds!: number;\n\n\t@prop({ type: AppForceUpdate })\n\tpublic userAppForceUpdate?: AppForceUpdate;\n\n\t@prop({ type: AppForceUpdate })\n\tpublic shopAppForceUpdate?: AppForceUpdate;\n\n\t@prop({ type: AppForceUpdate })\n\tpublic riderAppForceUpdate?: AppForceUpdate;\n\n\t@prop({\n\t\ttype: () => Map,\n\t\tof: Object as any,\n\t\tdefault: () => new Map(),\n\t})\n\tpublic enableFlags!: Map<string, any>;\n\n\t@prop({ type: CompanyInfo })\n\tpublic companyInfo?: CompanyInfo;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic showAreebaDefaultOtpPage?: boolean;\n\n\t@prop({ type: Boolean, default: true })\n\tpublic isProximityCheckEnabled?: boolean;\n}\n"]}
1
+ {"version":3,"file":"setting.model.js","sourceRoot":"/","sources":["libraries/mongo/models/setting.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA0D;AAC1D,8DAA2D;AAC3D,sEAA4D;AAC5D,kEAA6D;AAC7D,wEAA8D;AAC9D,wEAA8D;AAC9D,0EAAgE;AAChE,4EAAkE;AAClE,8EAAoE;AACpE,4EAAqE;AACrE,wEAAsE;AACtE,oFAAyE;AACzE,4FAA0E;AAC1E,kDAA0E;AAC1E,8FAA4E;AAC5E,kGAAuF;AACvF,sGAA2F;AAC3F,8FAA2F;AAGpF,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,2BAAU;IAE/B,eAAe,CAAmB;IAGlC,iBAAiB,CAAqB;IAGtC,aAAa,CAAiB;IAG9B,eAAe,CAAmB;IAGlC,cAAc,CAAkB;IAGhC,YAAY,CAAgB;IAG5B,0BAA0B,CAA8B;IAGxD,eAAe,CAAU;IAGzB,2BAA2B,CAAU;IAGrC,aAAa,CAAU;IAGvB,iBAAiB,CAAY;IAG7B,YAAY,CAA0B;IAGtC,kBAAkB,CAAU;IAG5B,8BAA8B,CAAU;IAGxC,KAAK,CAAY;IAGjB,eAAe,CAAmB;IAGlC,c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UAAU,EAAE,EAAE,CAAC;GAC/C,OAAO,CAiGnB","sourcesContent":["import { modelOptions, prop } from '@typegoose/typegoose';\nimport { WorkHourSetting } from './shared/work-hour.model';\nimport { CompanyInfo } from './embedded/company-info.model';\nimport { AppForceUpdate } from './embedded/app-force-update';\nimport { PlusSettings } from './embedded/plus-settings.model';\nimport { RiderSetting } from './embedded/rider-setting.model';\nimport { PayoutSetting } from './embedded/payout-setting.model';\nimport { CourierSetting } from './embedded/courier-setting.model';\nimport { CurrencySetting } from './embedded/currency-setting.model';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { RiderBatchesSettings } from './embedded/rider-batches.model';\nimport { ServiceFeeSetting } from './embedded/service-fee-setting.model';\nimport { DeliveryCharge } from './embedded/delivery-charge-setting.model';\nimport { LyxaTimeZoneEnum, PaymentMethod } from '../../../utilities/enum';\nimport { CustomerSupport } from './embedded/customer-support-numbers.model';\nimport { AgentNotificationSetting } from './embedded/agent-notification-setting.model';\nimport { BusinessDevelopmentSetting } from './embedded/business-development-setting.model';\nimport { CustomerSupportBatchesSettings } from './embedded/customer-support-batches.model';\n\n@modelOptions({ schemaOptions: { collection: 'settings' } })\nexport class Setting extends TimeStamps {\n\t@prop({ type: () => [DeliveryCharge] })\n\tpublic deliveryCharges: DeliveryCharge[];\n\n\t@prop({ type: ServiceFeeSetting })\n\tpublic serviceFeeSetting?: ServiceFeeSetting;\n\n\t@prop({ type: PayoutSetting })\n\tpublic payoutSetting?: PayoutSetting;\n\n\t@prop({ type: WorkHourSetting })\n\tpublic workHourSetting?: WorkHourSetting;\n\n\t@prop({ type: CourierSetting })\n\tpublic courierSetting?: CourierSetting;\n\n\t@prop({ type: RiderSetting })\n\tpublic riderSetting?: RiderSetting;\n\n\t@prop({ type: BusinessDevelopmentSetting })\n\tpublic businessDevelopmentSetting?: BusinessDevelopmentSetting;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic payLimitForUser?: number;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic concurrentOrderLimitForUser?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic vatPercentage?: number;\n\n\t@prop({ type: () => [Number], default: [] })\n\tpublic riderSearchRanges?: number[];\n\n\t@prop({ type: () => [RiderBatchesSettings], default: [] })\n\tpublic riderBatches?: RiderBatchesSettings[];\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistance?: number;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistanceInHomeScreen?: number;\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic units?: string[];\n\n\t@prop({ type: CurrencySetting })\n\tpublic currencySetting?: CurrencySetting;\n\n\t@prop({ type: () => [String], enum: PaymentMethod, default: [] })\n\tpublic paymentMethods?: PaymentMethod[];\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isGroupOrderEnabled?: boolean;\n\n\t@prop({ type: CustomerSupport })\n\tpublic customerSupport?: CustomerSupport;\n\n\t@prop({ type: () => [CustomerSupportBatchesSettings], default: [] })\n\tpublic customerSupportBatches?: CustomerSupportBatchesSettings[];\n\n\t@prop({ type: () => [PlusSettings], default: [] })\n\tpublic plusSettings?: PlusSettings[];\n\n\t@prop({ type: AgentNotificationSetting })\n\tpublic agentNotificationSetting?: AgentNotificationSetting;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic cashbackAmount?: number;\n\n\t@prop({ type: String, enum: LyxaTimeZoneEnum })\n\tpublic timezone?: LyxaTimeZoneEnum;\n\n\t@prop({ type: Number, min: 0, default: 600 })\n\tpublic bufferTimeInSeconds!: number;\n\n\t@prop({ type: AppForceUpdate })\n\tpublic userAppForceUpdate?: AppForceUpdate;\n\n\t@prop({ type: AppForceUpdate })\n\tpublic shopAppForceUpdate?: AppForceUpdate;\n\n\t@prop({ type: AppForceUpdate })\n\tpublic riderAppForceUpdate?: AppForceUpdate;\n\n\t@prop({\n\t\ttype: () => Map,\n\t\tof: Object as any,\n\t\tdefault: () => new Map(),\n\t})\n\tpublic enableFlags!: Map<string, any>;\n\n\t@prop({ type: CompanyInfo })\n\tpublic companyInfo?: CompanyInfo;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic showAreebaDefaultOtpPage?: boolean;\n}\n"]}
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
+ req: import("http").IncomingMessage;
8
9
  res: import("http").ServerResponse<import("http").IncomingMessage>;
9
10
  tokenType: TokenType | undefined;
10
- req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -4,9 +4,9 @@ interface RoleProtectedOptions {
4
4
  allowedRoles: string[];
5
5
  }
6
6
  export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
7
+ req: import("http").IncomingMessage;
7
8
  res: import("http").ServerResponse<import("http").IncomingMessage>;
8
9
  tokenType: import("../../auth").TokenType | undefined;
9
- req: import("http").IncomingMessage;
10
10
  requestId: string | undefined;
11
11
  entity: import("../context").EntityContext | undefined;
12
12
  usedRefreshToken: boolean | undefined;
@@ -3,9 +3,9 @@ interface PhoneVerifiedOptions {
3
3
  entityTypes: AuthEntityType[];
4
4
  }
5
5
  export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
6
+ req: import("http").IncomingMessage;
6
7
  res: import("http").ServerResponse<import("http").IncomingMessage>;
7
8
  tokenType: import("../../auth").TokenType | undefined;
8
- req: import("http").IncomingMessage;
9
9
  requestId: string | undefined;
10
10
  entity: import("../context").EntityContext | undefined;
11
11
  usedRefreshToken: boolean | undefined;
@@ -5,9 +5,9 @@ interface AuthOptions {
5
5
  autoRefresh?: boolean;
6
6
  }
7
7
  export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
8
+ req: import("http").IncomingMessage;
8
9
  res: import("http").ServerResponse<import("http").IncomingMessage>;
9
10
  tokenType: TokenType | undefined;
10
- req: import("http").IncomingMessage;
11
11
  requestId: string | undefined;
12
12
  entity: import("../context").EntityContext | undefined;
13
13
  usedRefreshToken: boolean | undefined;
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.4.289
25
+ Version: 1.4.290
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.4.289",
3
+ "version": "1.4.290",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -174,7 +174,6 @@ export declare enum AdminLogsUpdatedFieldsType {
174
174
  CURRENCY_SETTING = "currency_setting",
175
175
  PAYMENT_METHODS = "payment_methods",
176
176
  IS_GROUPED_ORDER_ENABLED = "is_grouped_order_enabled",
177
- IS_PROXIMITY_CHECK_ENABLED = "is_proximity_check_enabled",
178
177
  CUSTOMER_SUPPORT = "customer_support",
179
178
  CUSTOMER_SUPPORT_BATCHES = "customer_support_batches",
180
179
  WORK_HOUR_SETTINGS = "work_hour_settings",
@@ -204,7 +204,6 @@ var AdminLogsUpdatedFieldsType;
204
204
  AdminLogsUpdatedFieldsType["CURRENCY_SETTING"] = "currency_setting";
205
205
  AdminLogsUpdatedFieldsType["PAYMENT_METHODS"] = "payment_methods";
206
206
  AdminLogsUpdatedFieldsType["IS_GROUPED_ORDER_ENABLED"] = "is_grouped_order_enabled";
207
- AdminLogsUpdatedFieldsType["IS_PROXIMITY_CHECK_ENABLED"] = "is_proximity_check_enabled";
208
207
  AdminLogsUpdatedFieldsType["CUSTOMER_SUPPORT"] = "customer_support";
209
208
  AdminLogsUpdatedFieldsType["CUSTOMER_SUPPORT_BATCHES"] = "customer_support_batches";
210
209
  AdminLogsUpdatedFieldsType["WORK_HOUR_SETTINGS"] = "work_hour_settings";