@opengeni/codex 0.2.10 → 0.2.13

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/fetch.d.ts CHANGED
@@ -67,9 +67,9 @@ export type CodexSseFailureProjection = {
67
67
  * A provider terminal carried inside an accepted HTTP-200 stream. The OpenAI
68
68
  * SDK cannot turn that late terminal into a non-2xx APIError because headers
69
69
  * have already been accepted, so the body transform throws this equivalent
70
- * bounded shape. Provider-supplied message/param text is intentionally absent:
71
- * the worker may persist Error.message, while identifiers/classifications are
72
- * sufficient for retry, compaction, and incident diagnostics.
70
+ * bounded shape. Provider-supplied message/param text remains exact within the
71
+ * explicit terminal-field byte contract; retry classification is additive and
72
+ * never substitutes for the source diagnostic.
73
73
  */
74
74
  export declare class CodexStreamingTerminalError extends Error {
75
75
  readonly status: number;
@@ -80,5 +80,5 @@ export declare class CodexStreamingTerminalError extends Error {
80
80
  readonly responseStatus?: string;
81
81
  readonly headers: Headers;
82
82
  readonly error: Record<string, unknown>;
83
- constructor(projection: CodexSseFailureProjection, publicMessage: string);
83
+ constructor(projection: CodexSseFailureProjection);
84
84
  }
package/dist/index.d.ts CHANGED
@@ -11,5 +11,6 @@ export * from "./response-timeout";
11
11
  export * from "./fetch";
12
12
  export * from "./mcp-sanitize";
13
13
  export * from "./model-output-truncation";
14
+ export * from "./opaque-artifact";
14
15
  export * from "./realtime";
15
16
  export * from "./realtime-v3";
package/dist/index.js CHANGED
@@ -786,6 +786,27 @@ function isPreHeadersTimeoutError(error) {
786
786
 
787
787
  // src/fetch.ts
788
788
  import { randomUUID } from "crypto";
789
+
790
+ // src/opaque-artifact.ts
791
+ import { createHash } from "crypto";
792
+ function opaqueProviderArtifactFingerprint(item) {
793
+ if (!item || typeof item !== "object") return null;
794
+ const record = item;
795
+ if (record.type !== "reasoning" && record.type !== "compaction") return null;
796
+ const providerData = record.providerData && typeof record.providerData === "object" ? record.providerData : null;
797
+ const ciphertext = typeof record.encrypted_content === "string" && record.encrypted_content || typeof record.encryptedContent === "string" && record.encryptedContent || typeof providerData?.encrypted_content === "string" && providerData.encrypted_content || typeof providerData?.encryptedContent === "string" && providerData.encryptedContent || null;
798
+ if (!ciphertext) return null;
799
+ return `${record.type}:${createHash("sha256").update(ciphertext).digest("hex")}`;
800
+ }
801
+ function opaqueProviderArtifactFingerprints(input) {
802
+ if (!Array.isArray(input)) return [];
803
+ return input.flatMap((item) => {
804
+ const fingerprint = opaqueProviderArtifactFingerprint(item);
805
+ return fingerprint ? [fingerprint] : [];
806
+ });
807
+ }
808
+
809
+ // src/fetch.ts
789
810
  var CODEX_TRANSPORT_ERROR_HEADER = "x-opengeni-codex-transport-error";
790
811
  function headersCarryCodexTransportMarker(headers) {
791
812
  if (!headers || typeof headers !== "object") return false;
@@ -1122,6 +1143,7 @@ function codexSubscriptionFetch(base = globalThis.fetch) {
1122
1143
  }
1123
1144
  let callerWantsStream = true;
1124
1145
  let model;
1146
+ let requestOpaqueArtifacts = [];
1125
1147
  const nextInit = { ...init, headers };
1126
1148
  if (typeof init?.body === "string") {
1127
1149
  try {
@@ -1130,24 +1152,22 @@ function codexSubscriptionFetch(base = globalThis.fetch) {
1130
1152
  const normalized = normalizeCodexRequestBody(parsed, ctx.resolveModel);
1131
1153
  model = typeof normalized.model === "string" ? normalized.model : void 0;
1132
1154
  nextInit.body = JSON.stringify(normalized);
1155
+ requestOpaqueArtifacts = opaqueProviderArtifactFingerprints(normalized.input);
1133
1156
  } catch {
1134
1157
  }
1135
1158
  }
1159
+ ctx.onRequestOpaqueArtifacts?.({ requestId, fingerprints: requestOpaqueArtifacts });
1136
1160
  headers.set(
1137
1161
  "Idempotency-Key",
1138
1162
  authenticationAttempt === 0 ? requestId : `${requestId}:auth-${authenticationAttempt}`
1139
1163
  );
1140
1164
  if (process.env.CODEX_DEBUG) {
1141
- let keys = [];
1142
- if (typeof nextInit.body === "string") {
1143
- try {
1144
- keys = Object.keys(JSON.parse(nextInit.body));
1145
- } catch {
1146
- }
1147
- }
1148
- console.error(
1149
- `[codex-debug] POST ${rewritten} stream=${callerWantsStream} bodyKeys=[${keys.join(",")}]`
1150
- );
1165
+ console.error("[codex-debug] request dispatched", {
1166
+ method: "POST",
1167
+ origin: "codex-subscription",
1168
+ route: "codex_responses",
1169
+ stream: callerWantsStream
1170
+ });
1151
1171
  }
1152
1172
  let res;
1153
1173
  transportAttempt += 1;
@@ -1204,9 +1224,11 @@ function codexSubscriptionFetch(base = globalThis.fetch) {
1204
1224
  ctx.onUsageHeaders?.(usage);
1205
1225
  }
1206
1226
  if (process.env.CODEX_DEBUG && !res.ok) {
1207
- console.error(
1208
- `[codex-debug] <- ${res.status} requestId=${res.headers.get("x-request-id") ?? "unknown"}`
1209
- );
1227
+ console.error("[codex-debug] request failed", {
1228
+ origin: "codex-subscription",
1229
+ route: "codex_responses",
1230
+ status: res.status
1231
+ });
1210
1232
  }
1211
1233
  if (!res.ok) {
1212
1234
  return await bufferCodexErrorResponse(res);
@@ -1468,8 +1490,8 @@ var CodexStreamingTerminalError = class extends Error {
1468
1490
  responseStatus;
1469
1491
  headers;
1470
1492
  error;
1471
- constructor(projection, publicMessage) {
1472
- super(publicMessage);
1493
+ constructor(projection) {
1494
+ super(projection.error.message);
1473
1495
  this.name = "CodexStreamingTerminalError";
1474
1496
  this.status = projection.status;
1475
1497
  this.code = projection.error.code;
@@ -1487,6 +1509,8 @@ var CodexStreamingTerminalError = class extends Error {
1487
1509
  this.error = {
1488
1510
  type: projection.error.type,
1489
1511
  code: projection.error.code,
1512
+ message: projection.error.message,
1513
+ ...projection.error.param ? { param: projection.error.param } : {},
1490
1514
  ...projection.error.event_type ? { event_type: projection.error.event_type } : {},
1491
1515
  ...projection.error.response_id ? { response_id: projection.error.response_id } : {},
1492
1516
  ...projection.error.response_status ? { response_status: projection.error.response_status } : {},
@@ -1496,8 +1520,7 @@ var CodexStreamingTerminalError = class extends Error {
1496
1520
  };
1497
1521
  function codexSseFailureError(source, rawError, fallbackCode, publicMessage, metadata = {}) {
1498
1522
  return new CodexStreamingTerminalError(
1499
- codexSseFailureProjection(source, rawError, fallbackCode, publicMessage, metadata),
1500
- publicMessage
1523
+ codexSseFailureProjection(source, rawError, fallbackCode, publicMessage, metadata)
1501
1524
  );
1502
1525
  }
1503
1526
  function repairCodexStream(res) {
@@ -1762,13 +1785,15 @@ function inlineStructuredContentInRpcMessage(message) {
1762
1785
  return;
1763
1786
  }
1764
1787
  const structured = record.structuredContent;
1765
- if (structured === void 0 || structured === null) {
1766
- return;
1788
+ if (structured !== void 0 && structured !== null) {
1789
+ const text = typeof structured === "string" ? structured : JSON.stringify(structured);
1790
+ const content = Array.isArray(record.content) ? [...record.content] : [];
1791
+ content.push({ type: "text", text });
1792
+ record.content = content;
1793
+ }
1794
+ if (typeof structured !== "object" || structured === null || Array.isArray(structured)) {
1795
+ delete record.structuredContent;
1767
1796
  }
1768
- const text = typeof structured === "string" ? structured : JSON.stringify(structured);
1769
- const content = Array.isArray(record.content) ? [...record.content] : [];
1770
- content.push({ type: "text", text });
1771
- record.content = content;
1772
1797
  }
1773
1798
  function sanitizeMcpJsonBody(text, mapper = new ToolNameMapper(), namespaceSink) {
1774
1799
  try {
@@ -2607,6 +2632,8 @@ export {
2607
2632
  modelToolOutputSerializationBudgetTokens,
2608
2633
  normalizeCodexRequestBody,
2609
2634
  normalizeCodexUsage,
2635
+ opaqueProviderArtifactFingerprint,
2636
+ opaqueProviderArtifactFingerprints,
2610
2637
  parseCodexRateLimitResetConsumeResponse,
2611
2638
  parseCodexRateLimitResetCreditsDetails,
2612
2639
  parseCodexRateLimitResetCreditsSummary,