@opengeni/codex 0.2.16 → 0.2.17
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/index.js +15 -2
- package/dist/index.js.map +1 -1
- package/dist/request-context.d.ts +3 -0
- package/package.json +1 -1
- package/src/fetch.ts +21 -2
- package/src/request-context.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -821,6 +821,12 @@ function opaqueProviderArtifactFingerprints(input) {
|
|
|
821
821
|
}
|
|
822
822
|
|
|
823
823
|
// src/fetch.ts
|
|
824
|
+
function emitRequestPreparationDiagnostic(ctx, phase) {
|
|
825
|
+
try {
|
|
826
|
+
ctx.onRequestPreparationDiagnostic?.(phase);
|
|
827
|
+
} catch {
|
|
828
|
+
}
|
|
829
|
+
}
|
|
824
830
|
var CODEX_TRANSPORT_ERROR_HEADER = "x-opengeni-codex-transport-error";
|
|
825
831
|
var CODEX_REQUEST_BODY_NORMALIZED_HEADER = "x-opengeni-request-body-normalized";
|
|
826
832
|
var REPLAYABLE_REQUEST_BODY_FACTORY = Symbol.for("opengeni.replayable-request-body-factory");
|
|
@@ -1230,6 +1236,7 @@ function codexSubscriptionFetch(base = globalThis.fetch) {
|
|
|
1230
1236
|
if (!ctx) {
|
|
1231
1237
|
return base(input, init);
|
|
1232
1238
|
}
|
|
1239
|
+
emitRequestPreparationDiagnostic(ctx, "transport_entry");
|
|
1233
1240
|
const rawUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
|
|
1234
1241
|
const rewritten = rawUrl.replace(/(?<!\/codex)\/responses(\b|$)/, "/codex/responses$1");
|
|
1235
1242
|
const policy = resolveCodexResponseTimeoutPolicy(ctx.responseTimeoutPolicy);
|
|
@@ -1293,7 +1300,10 @@ function codexSubscriptionFetch(base = globalThis.fetch) {
|
|
|
1293
1300
|
throw new Error("Model request could not be prepared");
|
|
1294
1301
|
}
|
|
1295
1302
|
if (!bodyAlreadyNormalized) {
|
|
1296
|
-
ctx.onRequestOpaqueArtifacts?.({
|
|
1303
|
+
ctx.onRequestOpaqueArtifacts?.({
|
|
1304
|
+
requestId,
|
|
1305
|
+
fingerprints: requestOpaqueArtifacts
|
|
1306
|
+
});
|
|
1297
1307
|
}
|
|
1298
1308
|
headers.set(
|
|
1299
1309
|
"Idempotency-Key",
|
|
@@ -1319,6 +1329,7 @@ function codexSubscriptionFetch(base = globalThis.fetch) {
|
|
|
1319
1329
|
policy,
|
|
1320
1330
|
terminalOutcome: null
|
|
1321
1331
|
};
|
|
1332
|
+
emitRequestPreparationDiagnostic(ctx, "wire_request_ready");
|
|
1322
1333
|
await emitRequestEvent(audit, {
|
|
1323
1334
|
phase: "started",
|
|
1324
1335
|
responseObserved: false
|
|
@@ -1394,7 +1405,9 @@ function codexSubscriptionFetch(base = globalThis.fetch) {
|
|
|
1394
1405
|
return res;
|
|
1395
1406
|
};
|
|
1396
1407
|
try {
|
|
1397
|
-
|
|
1408
|
+
const token = await ctx.getToken();
|
|
1409
|
+
emitRequestPreparationDiagnostic(ctx, "credential_ready");
|
|
1410
|
+
let res = await attempt(token, 0);
|
|
1398
1411
|
if (res.status === 401) {
|
|
1399
1412
|
res = await attempt(await ctx.refresh(), 1);
|
|
1400
1413
|
}
|