@umituz/react-native-ai-pruna-provider 1.0.41 → 1.0.42
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.
|
|
3
|
+
"version": "1.0.42",
|
|
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,6 +22,7 @@ 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
26
|
} from "./request-store";
|
|
26
27
|
|
|
27
28
|
export class PrunaProvider implements IAIProvider {
|
|
@@ -87,7 +88,14 @@ export class PrunaProvider implements IAIProvider {
|
|
|
87
88
|
const sessionId = generationLogCollector.startSession();
|
|
88
89
|
generationLogCollector.log(sessionId, 'pruna-provider', `submitJob() for model: ${model}`);
|
|
89
90
|
try {
|
|
90
|
-
|
|
91
|
+
const submission = await queueOps.submitJob(prunaModel, input, apiKey, sessionId);
|
|
92
|
+
|
|
93
|
+
// Store requestId -> statusUrl mapping for getJobStatus/getJobResult
|
|
94
|
+
if (submission.statusUrl) {
|
|
95
|
+
storeRequestIdMapping(submission.requestId, submission.statusUrl, model);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return submission;
|
|
91
99
|
} finally {
|
|
92
100
|
generationLogCollector.endSession(sessionId);
|
|
93
101
|
}
|
|
@@ -96,12 +104,28 @@ export class PrunaProvider implements IAIProvider {
|
|
|
96
104
|
async getJobStatus(model: string, requestId: string): Promise<JobStatus> {
|
|
97
105
|
const apiKey = this.validateInit();
|
|
98
106
|
const prunaModel = this.validateModel(model);
|
|
107
|
+
|
|
108
|
+
// Look up statusUrl from requestId mapping
|
|
109
|
+
const statusUrl = getStatusUrlForRequestId(requestId);
|
|
110
|
+
if (statusUrl) {
|
|
111
|
+
return queueOps.getJobStatus(prunaModel, statusUrl, apiKey);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Fallback: assume requestId is actually a statusUrl (for direct calls with statusUrl)
|
|
99
115
|
return queueOps.getJobStatus(prunaModel, requestId, apiKey);
|
|
100
116
|
}
|
|
101
117
|
|
|
102
118
|
async getJobResult<T = unknown>(model: string, requestId: string): Promise<T> {
|
|
103
119
|
const apiKey = this.validateInit();
|
|
104
120
|
const prunaModel = this.validateModel(model);
|
|
121
|
+
|
|
122
|
+
// Look up statusUrl from requestId mapping
|
|
123
|
+
const statusUrl = getStatusUrlForRequestId(requestId);
|
|
124
|
+
if (statusUrl) {
|
|
125
|
+
return queueOps.getJobResult<T>(prunaModel, statusUrl, apiKey);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Fallback: assume requestId is actually a statusUrl (for direct calls with statusUrl)
|
|
105
129
|
return queueOps.getJobResult<T>(prunaModel, requestId, apiKey);
|
|
106
130
|
}
|
|
107
131
|
|
|
@@ -14,7 +14,9 @@ export interface ActiveRequest<T = unknown> {
|
|
|
14
14
|
|
|
15
15
|
const STORE_KEY = "__PRUNA_PROVIDER_REQUESTS__";
|
|
16
16
|
const TIMER_KEY = "__PRUNA_PROVIDER_CLEANUP_TIMER__";
|
|
17
|
+
const REQUEST_ID_KEY = "__PRUNA_PROVIDER_REQUEST_IDS__";
|
|
17
18
|
type RequestStore = Map<string, ActiveRequest>;
|
|
19
|
+
type RequestIdMap = Map<string, { statusUrl: string; model: string }>;
|
|
18
20
|
|
|
19
21
|
const CLEANUP_INTERVAL = 60_000;
|
|
20
22
|
const MAX_REQUEST_AGE = 3_660_000; // 61 min — must exceed max allowed timeout (1 hour)
|
|
@@ -138,6 +140,34 @@ export function stopAutomaticCleanup(): void {
|
|
|
138
140
|
stopCleanupTimer();
|
|
139
141
|
}
|
|
140
142
|
|
|
143
|
+
// ─── Request ID to StatusUrl Mapping ───────────────────────────────────────
|
|
144
|
+
|
|
145
|
+
function getRequestIdMap(): RequestIdMap {
|
|
146
|
+
const globalObj = globalThis as Record<string, unknown>;
|
|
147
|
+
if (!globalObj[REQUEST_ID_KEY]) {
|
|
148
|
+
globalObj[REQUEST_ID_KEY] = new Map();
|
|
149
|
+
}
|
|
150
|
+
return globalObj[REQUEST_ID_KEY] as RequestIdMap;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function storeRequestIdMapping(requestId: string, statusUrl: string, model: string): void {
|
|
154
|
+
getRequestIdMap().set(requestId, { statusUrl, model });
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export function getStatusUrlForRequestId(requestId: string): string | undefined {
|
|
158
|
+
const mapping = getRequestIdMap().get(requestId);
|
|
159
|
+
return mapping?.statusUrl;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function getModelForRequestId(requestId: string): string | undefined {
|
|
163
|
+
const mapping = getRequestIdMap().get(requestId);
|
|
164
|
+
return mapping?.model;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function removeRequestIdMapping(requestId: string): void {
|
|
168
|
+
getRequestIdMap().delete(requestId);
|
|
169
|
+
}
|
|
170
|
+
|
|
141
171
|
// Clear any leftover timer on module load (hot reload safety)
|
|
142
172
|
if (typeof globalThis !== "undefined") {
|
|
143
173
|
const existingTimer = getCleanupTimer();
|