@umituz/react-native-ai-generation-content 1.17.300 → 1.17.302

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-generation-content",
3
- "version": "1.17.300",
3
+ "version": "1.17.302",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native with result preview components",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -14,7 +14,7 @@ export const PartnerProfileRepository = {
14
14
  */
15
15
  getProfile: async (): Promise<PartnerProfile | null> => {
16
16
  try {
17
- const result = await storageRepository.getString(PARTNER_PROFILE_STORAGE_KEY, null);
17
+ const result = await storageRepository.getString(PARTNER_PROFILE_STORAGE_KEY, "");
18
18
  const data = unwrap(result, null);
19
19
 
20
20
  if (data) {
@@ -11,7 +11,7 @@ import type {
11
11
  } from "../../domain/entities";
12
12
  import { classifyError } from "../utils/error-classifier.util";
13
13
  import { ProgressManager } from "./progress-manager";
14
- import { JobPoller, type PollerConfig } from "./job-poller";
14
+ import { pollJob } from "./job-poller.service";
15
15
  import { ProviderValidator } from "./provider-validator";
16
16
 
17
17
  declare const __DEV__: boolean;
@@ -23,24 +23,20 @@ export interface OrchestratorConfig {
23
23
 
24
24
  class GenerationOrchestratorService {
25
25
  private progressManager = new ProgressManager();
26
- private jobPoller = new JobPoller();
27
26
  private providerValidator = new ProviderValidator();
27
+ private pollingConfig?: Partial<PollingConfig>;
28
+ private onStatusUpdateCallback?: (requestId: string, status: string) => Promise<void>;
28
29
 
29
30
  configure(config: OrchestratorConfig): void {
30
31
  if (typeof __DEV__ !== "undefined" && __DEV__) {
31
-
32
32
  console.log("[Orchestrator] configure() called", {
33
33
  hasPollingConfig: !!config.polling,
34
34
  hasStatusUpdate: !!config.onStatusUpdate,
35
35
  });
36
36
  }
37
37
 
38
- const pollerConfig: PollerConfig = {
39
- polling: config.polling,
40
- onStatusUpdate: config.onStatusUpdate,
41
- };
42
-
43
- this.jobPoller.configure(pollerConfig);
38
+ this.pollingConfig = config.polling;
39
+ this.onStatusUpdateCallback = config.onStatusUpdate;
44
40
  }
45
41
 
46
42
  async generate<T = unknown>(
@@ -50,7 +46,6 @@ class GenerationOrchestratorService {
50
46
  const startTime = Date.now();
51
47
 
52
48
  if (typeof __DEV__ !== "undefined" && __DEV__) {
53
-
54
49
  console.log("[Orchestrator] Generate started:", {
55
50
  model: request.model,
56
51
  capability: request.capability,
@@ -73,7 +68,6 @@ class GenerationOrchestratorService {
73
68
  updateProgress("submitting");
74
69
 
75
70
  if (typeof __DEV__ !== "undefined" && __DEV__) {
76
-
77
71
  console.log("[Orchestrator] Job submitted:", {
78
72
  requestId: submission.requestId,
79
73
  provider: provider.providerId,
@@ -82,26 +76,44 @@ class GenerationOrchestratorService {
82
76
 
83
77
  updateProgress("generating");
84
78
 
85
- const result = await this.jobPoller.pollForResult<T>(
79
+ const pollResult = await pollJob<T>({
86
80
  provider,
87
- request.model,
88
- submission.requestId,
89
- (status: import("../../domain/interfaces").JobStatus, attempt: number, config: PollingConfig) => {
90
- this.progressManager.updateProgressFromStatus(
91
- status,
92
- attempt,
93
- config,
94
- request.onProgress,
95
- );
81
+ model: request.model,
82
+ requestId: submission.requestId,
83
+ config: this.pollingConfig,
84
+ onStatusChange: async (status) => {
85
+ if (this.onStatusUpdateCallback) {
86
+ await this.onStatusUpdateCallback(submission.requestId, status.status);
87
+ }
96
88
  },
97
- );
89
+ onProgress: (progress: number) => {
90
+ // We map polling progress (0-100) to our "generating" stage progress
91
+ // Since we can't easily access the internal 'status' and 'attempt' here nicely without changing pollJob signature to pass them to onProgress
92
+ // But pollJob onProgress passes a number.
93
+ // The original code used: this.progressManager.updateProgressFromStatus(status, attempt, config...)
94
+ // pollJob calculates progress internally.
95
+ // We can just use the numeric progress directly for the converting.
96
+
97
+ // Actually, the original code had access to `status` object inside the callback.
98
+ // pollJob abstracts that away.
99
+ // However, progressManager.updateProgress takes (stage, subProgress).
100
+ // So we can just pass 'generating' and the percentage.
101
+
102
+ this.progressManager.updateProgress("generating", progress, request.onProgress);
103
+ }
104
+ });
105
+
106
+ if (!pollResult.success) {
107
+ throw pollResult.error;
108
+ }
109
+
110
+ const result = pollResult.data as T;
98
111
 
99
112
  updateProgress("completed");
100
113
 
101
114
  const duration = Date.now() - startTime;
102
115
 
103
116
  if (typeof __DEV__ !== "undefined" && __DEV__) {
104
-
105
117
  console.log("[Orchestrator] Generate completed:", {
106
118
  requestId: submission.requestId,
107
119
  duration: `${duration}ms`,
@@ -126,7 +138,6 @@ class GenerationOrchestratorService {
126
138
  const errorInfo = classifyError(error);
127
139
 
128
140
  if (typeof __DEV__ !== "undefined" && __DEV__) {
129
-
130
141
  console.error("[Orchestrator] Generation failed:", errorInfo);
131
142
  }
132
143
 
@@ -1,102 +0,0 @@
1
- /**
2
- * Job Poller
3
- * Handles polling logic for job status
4
- */
5
-
6
- import type { IAIProvider, JobStatus } from "../../domain/interfaces";
7
- import { DEFAULT_POLLING_CONFIG, type PollingConfig } from "../../domain/entities";
8
- import { isTransientError } from "../utils/error-classifier.util";
9
- import { createPollingDelay } from "../utils/polling-interval.util";
10
-
11
- declare const __DEV__: boolean;
12
-
13
- export interface PollerConfig {
14
- polling?: Partial<PollingConfig>;
15
- onStatusUpdate?: (requestId: string, status: string) => Promise<void>;
16
- }
17
-
18
- export class JobPoller {
19
- private config: PollerConfig = {};
20
-
21
- configure(config: PollerConfig): void {
22
- this.config = { ...this.config, ...config };
23
- }
24
-
25
- async pollForResult<T>(
26
- provider: IAIProvider,
27
- model: string,
28
- requestId: string,
29
- onStatusUpdate?: (status: JobStatus, attempt: number, config: PollingConfig) => void,
30
- ): Promise<T> {
31
- if (typeof __DEV__ !== "undefined" && __DEV__) {
32
-
33
- console.log("[JobPoller] pollForResult() started", {
34
- provider: provider.providerId,
35
- model,
36
- requestId,
37
- });
38
- }
39
-
40
- const config = {
41
- ...DEFAULT_POLLING_CONFIG,
42
- ...this.config.polling,
43
- };
44
-
45
- let consecutiveErrors = 0;
46
-
47
- for (let attempt = 0; attempt < config.maxAttempts; attempt++) {
48
- await createPollingDelay(attempt, config);
49
-
50
- if (typeof __DEV__ !== "undefined" && __DEV__ && attempt % 5 === 0) {
51
-
52
- console.log("[JobPoller] pollForResult() attempt", {
53
- attempt,
54
- maxAttempts: config.maxAttempts,
55
- });
56
- }
57
-
58
- try {
59
- const status = await provider.getJobStatus(model, requestId);
60
-
61
- consecutiveErrors = 0;
62
-
63
- onStatusUpdate?.(status, attempt, config);
64
-
65
- if (status.status === "COMPLETED") {
66
- if (typeof __DEV__ !== "undefined" && __DEV__) {
67
-
68
- console.log("[JobPoller] pollForResult() job COMPLETED", {
69
- requestId,
70
- attempt,
71
- });
72
- }
73
- return provider.getJobResult<T>(model, requestId);
74
- }
75
-
76
- if (status.status === "FAILED") {
77
- throw new Error("Job failed on provider");
78
- }
79
-
80
- await this.config.onStatusUpdate?.(requestId, status.status);
81
- } catch (error) {
82
- if (isTransientError(error)) {
83
- consecutiveErrors++;
84
-
85
- if (consecutiveErrors >= config.maxConsecutiveErrors) {
86
- throw error;
87
- }
88
-
89
- continue;
90
- }
91
-
92
- throw error;
93
- }
94
- }
95
-
96
- throw new Error(
97
- `Polling timeout after ${config.maxAttempts} attempts`,
98
- );
99
- }
100
- }
101
-
102
- export const jobPoller = new JobPoller();