@umituz/react-native-ai-fal-provider 3.2.32 → 3.2.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-fal-provider",
3
- "version": "3.2.32",
3
+ "version": "3.2.33",
4
4
  "description": "FAL AI provider for React Native - implements IAIProvider interface for unified AI generation",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -28,8 +28,6 @@ export class FalProvider implements IAIProvider {
28
28
  private apiKey: string | null = null;
29
29
  private initialized = false;
30
30
  private lastRequestKey: string | null = null;
31
- /** Tracks the active sessionId so callers can retrieve logs */
32
- private activeSessionId: string | null = null;
33
31
 
34
32
  initialize(config: AIProviderConfig): void {
35
33
  this.apiKey = config.apiKey;
@@ -80,7 +78,6 @@ export class FalProvider implements IAIProvider {
80
78
  this.validateInit();
81
79
  validateInput(model, input);
82
80
  const sessionId = generationLogCollector.startSession();
83
- this.activeSessionId = sessionId;
84
81
  generationLogCollector.log(sessionId, 'fal-provider', `submitJob() for model: ${model}`);
85
82
  const processedInput = await preprocessInput(input, sessionId);
86
83
  return queueOps.submitJob(model, processedInput);
@@ -108,7 +105,6 @@ export class FalProvider implements IAIProvider {
108
105
 
109
106
  // Start a fresh log session for this generation
110
107
  const sessionId = generationLogCollector.startSession();
111
- this.activeSessionId = sessionId;
112
108
  generationLogCollector.log(sessionId, TAG, `subscribe() called for model: ${model}`);
113
109
 
114
110
  const preprocessStart = Date.now();
@@ -140,7 +136,12 @@ export class FalProvider implements IAIProvider {
140
136
  .then((res) => {
141
137
  const totalElapsed = Date.now() - totalStart;
142
138
  generationLogCollector.log(sessionId, TAG, `Generation SUCCESS in ${totalElapsed}ms (preprocess: ${preprocessElapsed}ms)`);
143
- resolvePromise(res.result);
139
+ // Attach providerSessionId to result for concurrent-safe log retrieval
140
+ const result = res.result;
141
+ if (result && typeof result === 'object') {
142
+ Object.defineProperty(result, '__providerSessionId', { value: sessionId, enumerable: false });
143
+ }
144
+ resolvePromise(result);
144
145
  })
145
146
  .catch((error) => {
146
147
  const totalElapsed = Date.now() - totalStart;
@@ -163,7 +164,6 @@ export class FalProvider implements IAIProvider {
163
164
  validateInput(model, input);
164
165
 
165
166
  const sessionId = generationLogCollector.startSession();
166
- this.activeSessionId = sessionId;
167
167
  generationLogCollector.log(sessionId, 'fal-provider', `run() for model: ${model}`);
168
168
 
169
169
  const processedInput = await preprocessInput(input, sessionId);
@@ -173,13 +173,17 @@ export class FalProvider implements IAIProvider {
173
173
  throw new Error("Request cancelled by user");
174
174
  }
175
175
 
176
- return handleFalRun<T>(model, processedInput, sessionId, options);
176
+ const result = await handleFalRun<T>(model, processedInput, sessionId, options);
177
+ // Attach providerSessionId to result for concurrent-safe log retrieval
178
+ if (result && typeof result === 'object') {
179
+ Object.defineProperty(result, '__providerSessionId', { value: sessionId, enumerable: false });
180
+ }
181
+ return result;
177
182
  }
178
183
 
179
184
  reset(): void {
180
185
  cancelAllRequests();
181
186
  this.lastRequestKey = null;
182
- this.activeSessionId = null;
183
187
  this.apiKey = null;
184
188
  this.initialized = false;
185
189
  }
@@ -196,22 +200,21 @@ export class FalProvider implements IAIProvider {
196
200
  }
197
201
 
198
202
  /**
199
- * Get all log entries collected during the current/last generation session.
200
- * Returns empty array if no active session.
203
+ * Get log entries for a specific provider session.
204
+ * Extract sessionId from result.__providerSessionId for concurrent safety.
201
205
  */
202
- getSessionLogs(): LogEntry[] {
203
- if (!this.activeSessionId) return [];
204
- return generationLogCollector.getEntries(this.activeSessionId);
206
+ getSessionLogs(sessionId?: string): LogEntry[] {
207
+ if (!sessionId) return [];
208
+ return generationLogCollector.getEntries(sessionId);
205
209
  }
206
210
 
207
211
  /**
208
- * End the current log session and return all entries. Clears the buffer.
212
+ * End a provider log session and return all entries. Clears the buffer.
213
+ * Extract sessionId from result.__providerSessionId for concurrent safety.
209
214
  */
210
- endLogSession(): LogEntry[] {
211
- if (!this.activeSessionId) return [];
212
- const entries = generationLogCollector.endSession(this.activeSessionId);
213
- this.activeSessionId = null;
214
- return entries;
215
+ endLogSession(sessionId?: string): LogEntry[] {
216
+ if (!sessionId) return [];
217
+ return generationLogCollector.endSession(sessionId);
215
218
  }
216
219
  }
217
220