@umituz/react-native-ai-pruna-provider 1.0.42 → 1.0.43

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-pruna-provider",
3
- "version": "1.0.42",
3
+ "version": "1.0.43",
4
4
  "description": "Pruna AI provider for React Native - implements IAIProvider interface for unified AI generation",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -22,7 +22,8 @@ import type { LogEntry } from "../utils/log-collector";
22
22
  import {
23
23
  createRequestKey, getExistingRequest, storeRequest,
24
24
  removeRequest, cancelRequest, cancelAllRequests, hasActiveRequests,
25
- storeRequestIdMapping, getStatusUrlForRequestId, removeRequestIdMapping,
25
+ storeRequestIdMapping, storeImmediateResultMapping,
26
+ getStatusUrlForRequestId, getResponseUrlForRequestId, removeRequestIdMapping,
26
27
  } from "./request-store";
27
28
 
28
29
  export class PrunaProvider implements IAIProvider {
@@ -90,11 +91,16 @@ export class PrunaProvider implements IAIProvider {
90
91
  try {
91
92
  const submission = await queueOps.submitJob(prunaModel, input, apiKey, sessionId);
92
93
 
93
- // Store requestId -> statusUrl mapping for getJobStatus/getJobResult
94
+ // Store requestId -> statusUrl mapping for async jobs (requires polling)
94
95
  if (submission.statusUrl) {
95
96
  storeRequestIdMapping(submission.requestId, submission.statusUrl, model);
96
97
  }
97
98
 
99
+ // Store requestId -> responseUrl mapping for immediate results (already complete)
100
+ if (submission.responseUrl) {
101
+ storeImmediateResultMapping(submission.requestId, submission.responseUrl, model);
102
+ }
103
+
98
104
  return submission;
99
105
  } finally {
100
106
  generationLogCollector.endSession(sessionId);
@@ -105,7 +111,17 @@ export class PrunaProvider implements IAIProvider {
105
111
  const apiKey = this.validateInit();
106
112
  const prunaModel = this.validateModel(model);
107
113
 
108
- // Look up statusUrl from requestId mapping
114
+ // Check if this is an immediate result (already completed)
115
+ const responseUrl = getResponseUrlForRequestId(requestId);
116
+ if (responseUrl) {
117
+ // Result is already available
118
+ return {
119
+ status: "COMPLETED",
120
+ requestId,
121
+ };
122
+ }
123
+
124
+ // Look up statusUrl from requestId mapping (async job)
109
125
  const statusUrl = getStatusUrlForRequestId(requestId);
110
126
  if (statusUrl) {
111
127
  return queueOps.getJobStatus(prunaModel, statusUrl, apiKey);
@@ -119,7 +135,14 @@ export class PrunaProvider implements IAIProvider {
119
135
  const apiKey = this.validateInit();
120
136
  const prunaModel = this.validateModel(model);
121
137
 
122
- // Look up statusUrl from requestId mapping
138
+ // Check if this is an immediate result (already completed)
139
+ const responseUrl = getResponseUrlForRequestId(requestId);
140
+ if (responseUrl) {
141
+ // Return the immediate result
142
+ return { url: responseUrl } as T;
143
+ }
144
+
145
+ // Look up statusUrl from requestId mapping (async job)
123
146
  const statusUrl = getStatusUrlForRequestId(requestId);
124
147
  if (statusUrl) {
125
148
  return queueOps.getJobResult<T>(prunaModel, statusUrl, apiKey);
@@ -16,7 +16,7 @@ const STORE_KEY = "__PRUNA_PROVIDER_REQUESTS__";
16
16
  const TIMER_KEY = "__PRUNA_PROVIDER_CLEANUP_TIMER__";
17
17
  const REQUEST_ID_KEY = "__PRUNA_PROVIDER_REQUEST_IDS__";
18
18
  type RequestStore = Map<string, ActiveRequest>;
19
- type RequestIdMap = Map<string, { statusUrl: string; model: string }>;
19
+ type RequestIdMap = Map<string, { statusUrl?: string; responseUrl?: string; model: string }>;
20
20
 
21
21
  const CLEANUP_INTERVAL = 60_000;
22
22
  const MAX_REQUEST_AGE = 3_660_000; // 61 min — must exceed max allowed timeout (1 hour)
@@ -151,7 +151,11 @@ function getRequestIdMap(): RequestIdMap {
151
151
  }
152
152
 
153
153
  export function storeRequestIdMapping(requestId: string, statusUrl: string, model: string): void {
154
- getRequestIdMap().set(requestId, { statusUrl, model });
154
+ getRequestIdMap().set(requestId, { statusUrl, model, responseUrl: undefined });
155
+ }
156
+
157
+ export function storeImmediateResultMapping(requestId: string, responseUrl: string, model: string): void {
158
+ getRequestIdMap().set(requestId, { statusUrl: undefined, model, responseUrl });
155
159
  }
156
160
 
157
161
  export function getStatusUrlForRequestId(requestId: string): string | undefined {
@@ -159,6 +163,11 @@ export function getStatusUrlForRequestId(requestId: string): string | undefined
159
163
  return mapping?.statusUrl;
160
164
  }
161
165
 
166
+ export function getResponseUrlForRequestId(requestId: string): string | undefined {
167
+ const mapping = getRequestIdMap().get(requestId);
168
+ return mapping?.responseUrl;
169
+ }
170
+
162
171
  export function getModelForRequestId(requestId: string): string | undefined {
163
172
  const mapping = getRequestIdMap().get(requestId);
164
173
  return mapping?.model;