orangeslice 1.8.0 → 1.8.1
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/dist/api.js +7 -13
- package/package.json +1 -1
package/dist/api.js
CHANGED
|
@@ -4,21 +4,19 @@ exports.BATCH_NATIVE_FUNCTION_IDS = void 0;
|
|
|
4
4
|
exports.getFunctionType = getFunctionType;
|
|
5
5
|
exports.getBridgeResultEventName = getBridgeResultEventName;
|
|
6
6
|
exports.post = post;
|
|
7
|
-
const crypto_1 = require("crypto");
|
|
8
7
|
/**
|
|
9
8
|
* Runtime routing:
|
|
10
9
|
* - Non-direct calls submit to Railway batch-service /function
|
|
11
10
|
* - Direct calls submit to orangeslice.ai /api/function
|
|
12
11
|
* - Pending polling splits by function type:
|
|
13
|
-
* -
|
|
14
|
-
* - bridge: poll Next.js bridge-result route
|
|
12
|
+
* - default: poll batch-service /function/result
|
|
13
|
+
* - bridge: poll Next.js bridge-result route only when backend provides bridge metadata
|
|
15
14
|
*/
|
|
16
15
|
const BASE_URL = "https://enrichly-production.up.railway.app/function";
|
|
17
16
|
const DIRECT_BASE_URL = "https://orangeslice.ai/api/function";
|
|
18
17
|
const BRIDGE_POLL_URL = "https://orangeslice.ai/api/function/bridge-result";
|
|
19
18
|
const POLL_TIMEOUT_MS = 120000;
|
|
20
19
|
const DEFAULT_POLL_INTERVAL_MS = 1000;
|
|
21
|
-
const INTERNAL_CALLBACK_ID_KEY = "_orangesliceCallbackEventId";
|
|
22
20
|
exports.BATCH_NATIVE_FUNCTION_IDS = new Set(["b2b", "batchserp", "generateObject"]);
|
|
23
21
|
const BRIDGE_RESULT_EVENT_BY_FUNCTION_ID = {
|
|
24
22
|
firecrawl: "proxy/firecrawl.result",
|
|
@@ -161,11 +159,8 @@ async function pollBridgeUntilComplete(functionId, callbackEventId, eventName, f
|
|
|
161
159
|
async function post(functionId, payload, options = {}) {
|
|
162
160
|
const baseUrl = options.direct ? DIRECT_BASE_URL : BASE_URL;
|
|
163
161
|
const functionType = options.direct ? "batch-native" : getFunctionType(functionId);
|
|
164
|
-
const bridgeEventName = getBridgeResultEventName(functionId);
|
|
165
|
-
const callbackEventId = functionType === "bridge" && !options.direct && bridgeEventName ? (0, crypto_1.randomUUID)() : undefined;
|
|
166
|
-
const requestPayload = callbackEventId && functionType === "bridge" ? { ...payload, [INTERNAL_CALLBACK_ID_KEY]: callbackEventId } : payload;
|
|
167
162
|
const url = `${baseUrl}?functionId=${functionId}`;
|
|
168
|
-
const body = JSON.stringify(
|
|
163
|
+
const body = JSON.stringify(payload);
|
|
169
164
|
const res = await fetchWithRedirect(url, {
|
|
170
165
|
method: "POST",
|
|
171
166
|
headers: { "Content-Type": "application/json" },
|
|
@@ -181,12 +176,11 @@ async function post(functionId, payload, options = {}) {
|
|
|
181
176
|
if (isPendingResponse(data)) {
|
|
182
177
|
if (functionType === "bridge") {
|
|
183
178
|
const bridgePending = data;
|
|
184
|
-
const resolvedCallbackId = bridgePending.callbackEventId
|
|
185
|
-
const resolvedEventName = bridgePending.eventName ||
|
|
186
|
-
if (
|
|
187
|
-
|
|
179
|
+
const resolvedCallbackId = bridgePending.callbackEventId;
|
|
180
|
+
const resolvedEventName = bridgePending.eventName || getBridgeResultEventName(functionId);
|
|
181
|
+
if (resolvedCallbackId && resolvedEventName) {
|
|
182
|
+
return pollBridgeUntilComplete(functionId, resolvedCallbackId, resolvedEventName, bridgePending.pollAfterMs);
|
|
188
183
|
}
|
|
189
|
-
return pollBridgeUntilComplete(functionId, resolvedCallbackId, resolvedEventName, bridgePending.pollAfterMs);
|
|
190
184
|
}
|
|
191
185
|
return pollBatchUntilComplete(baseUrl, functionId, data);
|
|
192
186
|
}
|